in reply to Newx compiler warnings

xs_arrays.c:247: warning: format not a string literal and no format arguments

Normally, gcc issues this warning if *printf functions are being called with a non-literal first argument, and the respective warnings are enabled. (See also -Wformat, -Wformat-nonliteral, -Wformat-security in the gcc man page)  For example

#include <stdio.h> int main() { char foo[100]; scanf("%s", foo); printf(foo); /* compiler cannot inspect contents of foo */ return 0; }
$ gcc -Wformat -Wformat-security nonlit.c nonlit.c: In function 'main': nonlit.c:5: warning: format not a string literal and no format argumen +ts

It seems those warnings were enabled by default in gcc 4.2.1 (with my newer version I explicitly have to request them).

That said, I'm not sure where there would be something printf-related in your code... What is line 247?   Even the preprocessor expansion1 of your snippet reveals no (s|f)printf whatsoever:

SV* vec_zeros(int m) { int i; AV *myav; SV **svs; (svs = ((void)(sizeof(SV *) > 1 && (m) > ((size_t)~0)/sizeof(SV *) + && (Perl_croak_nocontext(PL_memory_wrap),0)), (SV **)Perl_safesysmal +loc((size_t)((m)*sizeof(SV *))))); for (i = 0; i < m; i++) { svs[i] = Perl_sv_newmortal(((PerlInterpreter *)pthread_getspec +ific((*Perl_Gthr_key_ptr(((void *)0)))))); Perl_sv_setnv(((PerlInterpreter *)pthread_getspecific((*Perl_G +thr_key_ptr(((void *)0))))), (SV*)svs[i],0.0f); } myav = Perl_av_make(((PerlInterpreter *)pthread_getspecific((*Perl +_Gthr_key_ptr(((void *)0))))), m,svs); Perl_safesysfree((void *)(svs)); return Perl_newRV_noinc(((PerlInterpreter *)pthread_getspecific((* +Perl_Gthr_key_ptr(((void *)0))))), (SV*) myav); }

Anyhow, most likely, you can just ignore the warning, or disable it with -Wno-format.

___

1 done with gcc option -E, on a Linux system, with a perl built with "usemymalloc=n" (like yours).

Replies are listed 'Best First'.
Re^2: Newx compiler warnings
by dave_the_m (Monsignor) on Mar 19, 2011 at 18:57 UTC
    Perl_croak_nocontext() is marked as being 'printf'-like, so it will generate similar warnings. The definition of the Newx macro (or rather the underlying MEM_WRAP_CHECK_1 macro) was fixed in 5.12.0 to avoid this (harmless) warning.

    Dave.