mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-11 15:06:14 +01:00
win32: don't assume the format specifier for the stdlib printf/scanf like functions
When using the mingw printf shims for C99 compat the msvc format specifiers don't work and the build fails. Ideally we would use glib functions which abstract this away, but in the error handler context we shouldn't call back into glib. And for scanf we don't have a glib wrapper. Instead call the "secure" versions provided by the win32 API (_snprintf_s/fprintf_s/sscanf_s) which mingw doesn't replace.
This commit is contained in:
parent
179fdc5239
commit
6095b9bd3c
@ -39,13 +39,14 @@ _g_win32_subst_pid_and_event (char *debugger,
|
||||
gsize pid_str_len;
|
||||
char event_str[STR_BUFFER_SIZE] = {0};
|
||||
gsize event_str_len;
|
||||
#undef STR_BUFFER_SIZE
|
||||
snprintf (pid_str, G_N_ELEMENTS (pid_str), "%lu", pid);
|
||||
|
||||
_snprintf_s (pid_str, STR_BUFFER_SIZE, G_N_ELEMENTS (pid_str), "%lu", pid);
|
||||
pid_str[G_N_ELEMENTS (pid_str) - 1] = 0;
|
||||
pid_str_len = strlen (pid_str);
|
||||
snprintf (event_str, G_N_ELEMENTS (pid_str), "%Iu", event);
|
||||
_snprintf_s (event_str, STR_BUFFER_SIZE, G_N_ELEMENTS (pid_str), "%Iu", event);
|
||||
event_str[G_N_ELEMENTS (pid_str) - 1] = 0;
|
||||
event_str_len = strlen (event_str);
|
||||
#undef STR_BUFFER_SIZE
|
||||
|
||||
while (cmdline[i] != 0 && dbg_i < debugger_size)
|
||||
{
|
||||
|
@ -1120,35 +1120,35 @@ g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo)
|
||||
return EXCEPTION_CONTINUE_EXECUTION;
|
||||
}
|
||||
|
||||
fprintf (stderr,
|
||||
"Exception code=0x%lx flags=0x%lx at 0x%p",
|
||||
er->ExceptionCode,
|
||||
er->ExceptionFlags,
|
||||
er->ExceptionAddress);
|
||||
fprintf_s (stderr,
|
||||
"Exception code=0x%lx flags=0x%lx at 0x%p",
|
||||
er->ExceptionCode,
|
||||
er->ExceptionFlags,
|
||||
er->ExceptionAddress);
|
||||
|
||||
switch (er->ExceptionCode)
|
||||
{
|
||||
case EXCEPTION_ACCESS_VIOLATION:
|
||||
fprintf (stderr,
|
||||
". Access violation - attempting to %s at address 0x%p\n",
|
||||
er->ExceptionInformation[0] == 0 ? "read data" :
|
||||
er->ExceptionInformation[0] == 1 ? "write data" :
|
||||
er->ExceptionInformation[0] == 8 ? "execute data" :
|
||||
"do something bad",
|
||||
(void *) er->ExceptionInformation[1]);
|
||||
fprintf_s (stderr,
|
||||
". Access violation - attempting to %s at address 0x%p\n",
|
||||
er->ExceptionInformation[0] == 0 ? "read data" :
|
||||
er->ExceptionInformation[0] == 1 ? "write data" :
|
||||
er->ExceptionInformation[0] == 8 ? "execute data" :
|
||||
"do something bad",
|
||||
(void *) er->ExceptionInformation[1]);
|
||||
break;
|
||||
case EXCEPTION_IN_PAGE_ERROR:
|
||||
fprintf (stderr,
|
||||
". Page access violation - attempting to %s at address 0x%p with status %Ix\n",
|
||||
er->ExceptionInformation[0] == 0 ? "read from an inaccessible page" :
|
||||
er->ExceptionInformation[0] == 1 ? "write to an inaccessible page" :
|
||||
er->ExceptionInformation[0] == 8 ? "execute data in page" :
|
||||
"do something bad with a page",
|
||||
(void *) er->ExceptionInformation[1],
|
||||
er->ExceptionInformation[2]);
|
||||
fprintf_s (stderr,
|
||||
". Page access violation - attempting to %s at address 0x%p with status %Ix\n",
|
||||
er->ExceptionInformation[0] == 0 ? "read from an inaccessible page" :
|
||||
er->ExceptionInformation[0] == 1 ? "write to an inaccessible page" :
|
||||
er->ExceptionInformation[0] == 8 ? "execute data in page" :
|
||||
"do something bad with a page",
|
||||
(void *) er->ExceptionInformation[1],
|
||||
er->ExceptionInformation[2]);
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, "\n");
|
||||
fprintf_s (stderr, "\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,7 @@ main (int argc,
|
||||
#ifndef G_OS_WIN32
|
||||
# define SCAN_FORMAT64 FORMAT64
|
||||
#else
|
||||
# define sscanf sscanf_s
|
||||
# define SCAN_FORMAT64 "%I64d %I64u\n"
|
||||
#endif
|
||||
string = g_strdup_printf (FORMAT64, gi64t1, gu64t1);
|
||||
@ -138,6 +139,7 @@ main (int argc,
|
||||
#ifndef G_OS_WIN32
|
||||
# define SCAN_FORMATSIZE FORMATSIZE
|
||||
#else
|
||||
# define sscanf sscanf_s
|
||||
# define SCAN_FORMATSIZE "%Id %Iu\n"
|
||||
#endif
|
||||
string = g_strdup_printf (FORMATSIZE, gsst1, gst1);
|
||||
|
Loading…
Reference in New Issue
Block a user