if (abs(diff) > 2)
{
- fprintf(stderr, "%zd %02X : %02X diff=%lf\n", x, val1, val2, diff);
+ fprintf(stderr, "%lu %02X : %02X diff=%lf\n", (unsigned long)x, val1, val2, diff);
return FALSE;
}
}
while((x < halfPad) && (*esrc++ != 'A'))
x++;
- fprintf(stderr, "Buffer underflow detected %02x != %02X %s [%zd-%zd]\n",
- d, 'A', buffer, start, x);
+ fprintf(stderr, "Buffer underflow detected %02x != %02X %s [%lu-%lu]\n",
+ d, 'A', buffer, (unsigned long)start, (unsigned long)x);
return FALSE;
}
if(d != 'A')
while((x < halfPad) && (*esrc++ != 'A'))
x++;
- fprintf(stderr, "Buffer overflow detected %02x != %02X %s [%zd-%zd]\n",
- d, 'A', buffer, start, x);
+ fprintf(stderr, "Buffer overflow detected %02x != %02X %s [%lu-%lu]\n",
+ d, 'A', buffer, (unsigned long)start, (unsigned long)x);
return FALSE;
}
}
{
size_t line_len = (data->max > 1024) ? data->max : 1024;
size_t i;
- char* lines = calloc(data->used + 1, sizeof(char *) * line_len);
- char** vlines = (char**) lines;
+ size_t array_size = data->used * sizeof(char*);
+ size_t lines_size = data->used * line_len;
+ char **vlines = calloc(1, array_size + lines_size);
+
backtrace_symbol_t* symbols = calloc(data->used, sizeof(backtrace_symbol_t));
- if (!lines || !symbols)
+ if (!vlines || !symbols)
{
- if (lines)
- free(lines);
-
- if (symbols)
- free(symbols);
-
+ free(vlines);
+ free(symbols);
return NULL;
}
- /* To allow a char** malloced array to be returned, allocate n+1 lines
- * and fill in the first lines[i] char with the address of lines[(i+1) * 1024] */
+ /* Set the pointers in the allocated buffer's initial array section */
for (i = 0; i < data->used; i++)
- vlines[i] = &lines[(i + 1) * line_len];
+ vlines[i] = (char*)vlines + array_size + i * line_len;
fkt->get_backtrace_symbols(data->buffer, data->used, symbols);
if (used)
*used = data->used;
- return (char**) lines;
+ return vlines;
}
#elif (defined(_WIN32) || defined(_WIN64)) && !defined(_UWP)
{
size_t line_len = 1024;
HANDLE process = GetCurrentProcess();
t_win_stack* data = (t_win_stack*) buffer;
- char *lines = calloc(data->used + 1, sizeof(char*) * line_len);
- char **vlines = (char**) lines;
+ size_t array_size = data->used * sizeof(char*);
+ size_t lines_size = data->used * line_len;
+ char **vlines = calloc(1, array_size + lines_size);
SYMBOL_INFO* symbol = calloc(sizeof(SYMBOL_INFO) + line_len * sizeof(char), 1);
IMAGEHLP_LINE64* line = (IMAGEHLP_LINE64*) calloc(1, sizeof(IMAGEHLP_LINE64));
- if (!lines || !symbol || !line)
+ if (!vlines || !symbol || !line)
{
- if (lines)
- free(lines);
-
- if (symbol)
- free(symbol);
-
- if (line)
- free(line);
-
+ free(vlines);
+ free(symbol);
+ free(line);
return NULL;
}
symbol->MaxNameLen = line_len;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
- /* To allow a char** malloced array to be returned, allocate n+1 lines
- * and fill in the first lines[i] char with the address of lines[(i+1) * 1024] */
+ /* Set the pointers in the allocated buffer's initial array section */
for (i = 0; i < data->used; i++)
- vlines[i] = &lines[(i + 1) * line_len];
+ vlines[i] = (char*)vlines + array_size + i * line_len;
for (i = 0; i < data->used; i++)
{
free(symbol);
free(line);
- return (char**) lines;
+ return vlines;
}
#else
LOGF(support_msg);
if (msg)
{
for (x=0; x<used; x++)
- WLog_LVL(tag, level, "%zd: %s\n", x, msg[x]);
+ WLog_LVL(tag, level, "%lu: %s\n", (unsigned long)x, msg[x]);
}
winpr_backtrace_free(stack);
}
if (!buffer)
{
- WLog_ERR(tag, "malloc(%zd) failed with [%d] %s", blen, errno, strerror(errno));
+ WLog_ERR(tag, "malloc(%lu) failed with [%d] %s", (unsigned long)blen, errno, strerror(errno));
return;
}
if (!buffer)
{
- WLog_ERR(tag, "malloc(%zd) failed with [%d] %s", llen, errno, strerror(errno));
+ WLog_ERR(tag, "malloc(%lu) failed with [%d] %s", (unsigned long)llen, errno, strerror(errno));
return;
}
if (msg)
{
for (x=0; x<used; x++)
- printf("%zd: %s\n", x, msg[x]);
+ printf("%lu: %s\n", (unsigned long)x, msg[x]);
rc = 0;
}
winpr_backtrace_symbols_fd(stack, fileno(stdout));
int success = 0;
void *a = NULL;
long src_size;
- FILE *fsrc = fopen(src, "r");
+ FILE *fsrc = fopen(src, "rb");
if (!fsrc)
{
if (!a)
{
- fprintf(stderr, "Failed malloc %zd bytes\n", src_size);
+ fprintf(stderr, "Failed malloc %ld bytes\n", src_size);
goto cleanup;
}
if (fread(a, sizeof(char), src_size, fsrc) != src_size)
{
- fprintf(stderr, "Failed read %zd bytes\n", src_size);
+ fprintf(stderr, "Failed read %ld bytes\n", src_size);
goto cleanup;
}
return FALSE;
for (i=0; i<used; i++)
- if (fprintf(stderr, "%s: %zd: %s\n", fkt, i, msg[i]) < 0)
+ if (fprintf(stderr, "%s: %lu: %s\n", fkt, (unsigned long)i, msg[i]) < 0)
return FALSE;
#endif