mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 22:03:42 -07:00
fix realloc properly
This commit is contained in:
parent
988b61cfa5
commit
d0489da611
1 changed files with 18 additions and 12 deletions
|
@ -436,30 +436,36 @@ static void set_my_user_directory(void) {
|
||||||
// if not found, default to current directory
|
// if not found, default to current directory
|
||||||
if (my_user_directory == NULL) {
|
if (my_user_directory == NULL) {
|
||||||
|
|
||||||
char *cwd_Buffer = NULL;
|
|
||||||
uint16_t pathLen = FILENAME_MAX; // should be a good starting point
|
uint16_t pathLen = FILENAME_MAX; // should be a good starting point
|
||||||
bool error = false;
|
bool error = false;
|
||||||
|
char *cwd_buffer = (char *)calloc(pathLen, sizeof(uint8_t));
|
||||||
|
|
||||||
cwd_Buffer = (char *)calloc(pathLen, sizeof(uint8_t));
|
while (!error && (GetCurrentDir(cwd_buffer, pathLen) == NULL)) {
|
||||||
|
|
||||||
while (!error && (GetCurrentDir(cwd_Buffer, pathLen) == NULL)) {
|
|
||||||
if (errno == ERANGE) { // Need bigger buffer
|
if (errno == ERANGE) { // Need bigger buffer
|
||||||
pathLen += 10; // if buffer was too small add 10 characters and try again
|
pathLen += 10; // if buffer was too small add 10 characters and try again
|
||||||
cwd_Buffer = realloc(cwd_Buffer, pathLen);
|
char *tmp = realloc(cwd_buffer, pathLen);
|
||||||
} else {
|
if (tmp == NULL) {
|
||||||
error = true;
|
PrintAndLogEx(WARNING, "failed to allocate memory");
|
||||||
free(cwd_Buffer);
|
free(cwd_buffer);
|
||||||
cwd_Buffer = NULL;
|
return;
|
||||||
}
|
}
|
||||||
printf("Len... %d\n", pathLen);
|
cwd_buffer = tmp;
|
||||||
|
} else {
|
||||||
|
free(cwd_buffer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PrintAndLogEx(NORMAL, "Len... %d", pathLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
|
||||||
for (int i = 0; i < strlen(cwd_Buffer); i++)
|
for (int i = 0; i < strlen(cwd_buffer); i++) {
|
||||||
if (cwd_Buffer[i] == '\\') cwd_Buffer[i] = '/';
|
if (cwd_buffer[i] == '\\') {
|
||||||
|
cwd_buffer[i] = '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my_user_directory = cwd_Buffer;
|
my_user_directory = cwd_buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue