Skip to content

Commit 49d95ca

Browse files
committed
locale.c: fix format type for __LINE__ output (debugging)
On some platforms, building a -DDEBUGGING perl triggers the following compiler warnings: In file included from locale.c:385: locale.c: In function ‘S_bool_setlocale_2008_i’: locale.c:2494:29: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 7 has type ‘int’ [-Wformat=] "bool_setlocale_2008_i: creating new object" \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ perl.h:4983:33: note: in definition of macro ‘DEBUG__’ DEBUG_PRE_STMTS a; DEBUG_POST_STMTS \ ^ locale.c:2493:7: note: in expansion of macro ‘DEBUG_L’ DEBUG_L(PerlIO_printf(Perl_debug_log, \ ^~~~~~~ locale.c:2523:17: note: in expansion of macro ‘DEBUG_NEW_OBJECT_FAILED’ DEBUG_NEW_OBJECT_FAILED(category_names[index], new_locale, ^~~~~~~~~~~~~~~~~~~~~~~ In file included from locale.c:322: config.h:4052:18: note: format string is defined here #define U32uf "lu" /**/ This is because the code tries to format __LINE__ with a varargs function using %"LINE_Tf". Things are slightly tricky here because in a varargs function, no type context is available, so the format string absolutely has to match the intrinsic type of each argument. The __LINE__ macro expands to a simple (decimal) integer constant. According to C, such a constant has type int if its value fits, otherwise unsigned int if it fits, otherwise long int, etc. None of the *.c files in the perl distribution exceed 32767 lines (the minimum INT_MAX required by C), so even on ancient 16-bit systems, our __LINE__ will always be of type int. The %"LINE_Tf" format is designed to match a line_t argument, not int. (On some platforms, line_t is defined as unsigned long and incompatible with int for formatting purposes.) Therefore it is an error to use %"LINE_Tf" with __LINE__. One way to fix this is to convert the argument to match the format string: ... %"LINE_Tf" ...", (line_t)__LINE__. The other way is to change the format string to match the (int) argument: "... %d ...", __LINE__. Option 1 is what is used elsewhere in locale.c, so use line_t consistently for all line numbers.
1 parent a01c235 commit 49d95ca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

locale.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,14 +2495,14 @@ S_bool_setlocale_2008_i(pTHX_
24952495
" while freeing %p; called from %" LINE_Tf \
24962496
" via %" LINE_Tf "\n", \
24972497
category, locale, new, old, \
2498-
caller_line, __LINE__))
2498+
caller_line, (line_t)__LINE__))
24992499
# define DEBUG_NEW_OBJECT_FAILED(category, locale, basis_obj) \
25002500
DEBUG_L(PerlIO_printf(Perl_debug_log, \
25012501
"bool_setlocale_2008_i: creating new object" \
25022502
" for (%s '%s') from %p failed; called from %" \
25032503
LINE_Tf " via %" LINE_Tf "\n", \
25042504
category, locale, basis_obj, \
2505-
caller_line, __LINE__));
2505+
caller_line, (line_t)__LINE__));
25062506

25072507
/* Ready to create a new locale by modification of the existing one.
25082508
*

0 commit comments

Comments
 (0)