Skip to content

Commit

Permalink
Merge pull request #6 from mephistolist/main
Browse files Browse the repository at this point in the history
Resolved Warnings
  • Loading branch information
AleksArt000 authored Oct 30, 2024
2 parents a91260e + 81d4d1a commit 1e16e2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/mem.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Expand All @@ -8,8 +7,6 @@

#include "../cutils.h"



#define MAX_PTRS 8192

typedef struct {
Expand Down Expand Up @@ -97,15 +94,24 @@ void* dbg_calloc(size_t nmemb, size_t size, char* file, int line)
return ptr;
}

void* dbg_realloc(void* ptr, size_t size, char* file, int line)
{
void* dbg_realloc(void* ptr, size_t size, char* file, int line) {
dbg(4, "dbg_realloc: %s:%d %p %zu->%zu bytes", file, line, ptr, malloc_usable_size(ptr), size);

// Unlog the pointer before reallocating
unlog_ptr(ptr, file, line);

// Reallocate memory
void* newptr = realloc(ptr, size);

// Check for allocation failure
if (newptr == NULL) {
msg(ERROR, "\trealloc failed");
return NULL; // Return NULL on failure
}
unlog_ptr(ptr, file, line);

// Log the new pointer
log_ptr(newptr, file, line);

return newptr;
}

Expand Down Expand Up @@ -136,4 +142,3 @@ void dbg_free(void* ptr, char* file, int line)
}
free(ptr);
}

5 changes: 3 additions & 2 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ int mvlink(char* old_path,char* new_path)
//strncpy(new_link,parent_path,strlen(parent_path));

// add the separator
if (new_link[strlen(new_link)-1] != '/') strncat(new_link,"/",1);
if (new_link[strlen(new_link) - 1] != '/') {
strncat(new_link, "/", 2); // Reserve space for the null terminator
}

//strncat(new_link,rel_path,strlen(rel_path));

Expand Down Expand Up @@ -289,4 +291,3 @@ int mvsp(char* old_path,char* new_path)

return 0;
}

0 comments on commit 1e16e2f

Please sign in to comment.