i have a quesstion about gcc warning
-
when i complier these codes, the warning will come :
static void err_doit(int errnoflag, int level, const char* fmt, va_list ap)
{
int errno_save, n;
char buf[MAXLINE+1];errno\_save = errno; //value caller might want printed #ifdef HAVE\_VSNPRINTF vsnprintf(buf, MAXLINE, fmt, ap); //this is safe #else vsprintf(buf, fmt, ap); //this is not safe #endif n = strlen(buf); if(errnoflag) snprintf((char\*)(buf+n), MAXLINE-n, ";%s", strerror(errno\_save)); strcat(buf, "\\n"); //const char\* temp = buf; if(daemon\_proc) { syslog(level, (const char\*)buf); //98 //syslog(level, temp); } else { fflush(stdout); //in case stdout and stderr are the same fputs(buf, stderr); fflush(stderr); } return;
}
</pre>the warnning is:
In file included from str_cli.c:2,
from tcpcli01.c:2:
error.c: In function ‘void err_doit(int, int, const char*, char*)’:
error.c:98: warning: format not a string literal and no format argumentsi this warning, for i don't make buf to (const char*), but i try, it don't work.
please give me some advices, thank you -
when i complier these codes, the warning will come :
static void err_doit(int errnoflag, int level, const char* fmt, va_list ap)
{
int errno_save, n;
char buf[MAXLINE+1];errno\_save = errno; //value caller might want printed #ifdef HAVE\_VSNPRINTF vsnprintf(buf, MAXLINE, fmt, ap); //this is safe #else vsprintf(buf, fmt, ap); //this is not safe #endif n = strlen(buf); if(errnoflag) snprintf((char\*)(buf+n), MAXLINE-n, ";%s", strerror(errno\_save)); strcat(buf, "\\n"); //const char\* temp = buf; if(daemon\_proc) { syslog(level, (const char\*)buf); //98 //syslog(level, temp); } else { fflush(stdout); //in case stdout and stderr are the same fputs(buf, stderr); fflush(stderr); } return;
}
</pre>the warnning is:
In file included from str_cli.c:2,
from tcpcli01.c:2:
error.c: In function ‘void err_doit(int, int, const char*, char*)’:
error.c:98: warning: format not a string literal and no format argumentsi this warning, for i don't make buf to (const char*), but i try, it don't work.
please give me some advices, thank youThe specification for
syslog()
isvoid syslog(int priority, const char *format, ...);
and your call uses
buf
as the format parameter, but its content does not contain any format control characters, and your call does not include any parameters. If you rewrite it assyslog(level, "%s", buf);
it should work OK.
Just say 'NO' to evaluated arguments for diadic functions! Ash