2
所以我試圖建立freewrl android庫,這是在本機android代碼,這意味着在C.我不熟悉C,並且因爲包含了構建腳本,所以應該開箱即用。 - 它不是。 修復了一些小問題之後,這是我看現在:FreeWRL,「格式不是字符串文字和沒有格式參數」
/opt/freewrl/Android/jni/../../freex3d/src/lib/main/ConsoleMessage.c: In function 'fwvsnprintf':
/opt/freewrl/Android/jni/../../freex3d/src/lib/main/ConsoleMessage.c:333:4: error: format not a string literal and no format arguments [-Werror=format-security]
cc1: some warnings being treated as errors
make: *** [/opt/freewrl/Android/obj/local/armeabi/objs/FreeWRL/__/__/freex3d/src/lib/main/ConsoleMessage.o] Error 1
在ConsoleMessage.c的代碼相關的是以下幾點:
count += sprintf(tempbuf, format);/* printf it verbatim */
哪個部分以下構建體或功能:
int fwvsnprintf(char *buffer,int buffer_length, const char *fmt, va_list ap)
{
int i,j,count;
//char tempbuf[STRING_LENGTH];
//char format[STRING_LENGTH];
char *tempbuf;
char *format;
char c;
double d;
unsigned u;
char *s;
void *v;
tempbuf = malloc(buffer_length);
format = malloc(buffer_length);
count = 0;
buffer[0] = '\0';
while (*fmt)
{
tempbuf[0] = '\0';
for (j = 0; fmt[j] && fmt[j] != '%'; j++) {
format[j] = fmt[j]; /* not a format string */
}
if (j) {
format[j] = '\0';
count += sprintf(tempbuf, format);/* printf it verbatim */
fmt += j;
} else {
for (j = 0; !isalpha(fmt[j]); j++) { /* find end of format specifier */
format[j] = fmt[j];
if (j && fmt[j] == '%') /* special case printing '%' */
break;
}
format[j] = fmt[j]; /* finish writing specifier */
format[j + 1] = '\0'; /* don't forget NULL terminator */
fmt += j + 1;
switch (format[j]) { /* cases for all specifiers */
case 'd':
case 'i': /* many use identical actions */
i = va_arg(ap, int); /* process the argument */
count += sprintf(tempbuf, format, i); /* and printf it */
break;
case 'o':
case 'x':
case 'X':
case 'u':
u = va_arg(ap, unsigned);
count += sprintf(tempbuf, format, u);
break;
case 'c':
c = (char) va_arg(ap, int); /* must cast! */
count += sprintf(tempbuf, format, c);
break;
case 's':
s = va_arg(ap, char *);
/* limit string to a certain length */
if ((strlen(s) + count) > buffer_length) {
char tmpstr[100];
int ltc;
ltc = (int) strlen(s);
if (ltc>80) ltc=80;
strncpy (tmpstr, s, ltc);
tmpstr[ltc] = '.'; ltc++;
tmpstr[ltc] = '.'; ltc++;
tmpstr[ltc] = '.'; ltc++;
tmpstr[ltc] = '\0';
count += sprintf (tempbuf, format, tmpstr);
} else count += sprintf(tempbuf, format, s);
break;
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
d = va_arg(ap, double);
count += sprintf(tempbuf, format, d);
break;
case 'p':
v = va_arg(ap, void *);
count += sprintf(tempbuf, format, v);
break;
case 'n':
count += sprintf(tempbuf, "%d", count);
break;
case '%':
count += sprintf(tempbuf, "%%");
break;
default:
ERROR_MSG("ConsoleMessage: invalid format specifier: %c\n", format[j]);
}
}
if((strlen(tempbuf) + strlen(buffer)) < (buffer_length) -10)
{
strcat (buffer,tempbuf);
}
}
free(tempbuf);
free(format);
return 1;
}
所以據我所看到的,format
充滿的fmt
的內容,這是一個參數,直到01閱讀。 tempbuf
看起來像'\ 0',所以對我來說是一個空字節。 但是,就我所知,所以我很感激任何幫助,因爲我正在努力建立這個庫。 預先感謝您。
謝謝! 「%s」修正了它。 – damian