News:

Simutrans Wiki Manual
The official on-line manual for Simutrans. Read and contribute.

gui/money_frame.cc error

Started by Vonjo, January 21, 2013, 05:37:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Vonjo

I got this error:


===> CXX gui/money_frame.cc
gui/money_frame.cc: In member function 'virtual void money_frame_t::zeichnen(koord, koord)':
gui/money_frame.cc:439:66: error: format not a string literal and no format arguments [-Werror=format-security]
cc1plus: some warnings being treated as errors
make[1]: *** [build/default/gui/money_frame.o] Error 1


https://launchpadlibrarian.net/128868183/buildlog_ubuntu-precise-i386.simutrans_112.1-1ppa1_FAILEDTOBUILD.txt.gz

In money_frame.cc:439 :
sprintf( str_buf[15], translator::translate("Scenario lost!") );

Ters

I don't get that error. I don't see why it should be an error either. It barely deserves to be a warning, which I don't get either.

Dwachs

If the translate-call returns a string which has format specifiers (think of %s) then this piece of code could make problems. Afaict the translator code checks for wrong formt specifiers.

This sprintf call could be strcpy ...
Parsley, sage, rosemary, and maggikraut.

Ters

Quote from: Dwachs on January 21, 2013, 07:39:01 AM
If the translate-call returns a string which has format specifiers (think of %s) then this piece of code could make problems. Afaict the translator code checks for wrong formt specifiers.

Hence the barely.

I'm still not sure why the compiler is so upset about this. Is passinng dynamic strings, but completely forgetting the format arguments so much more common than passing too few format arguments? Or would it error even if format arguments were passed? If so, then there are lots of problematic *printf calls in Simutrans.

Vonjo

Quote from: Ters on January 21, 2013, 05:46:50 AM
I don't get that error. I don't see why it should be an error either. It barely deserves to be a warning, which I don't get either.
Yeah, some system treat it as error, some just treat it as warning.
I managed to resolve it by adding -Wno-error=format-security flag.
But is it really a problem?

However, from the buildlog, I can see that -Wformat-security warning only raised once (in gui/money_frame.cc:439:66).

Ters

That means the compiler freaks out on just one of, for all it knows, multiple possible places for format argument mismatch errors. I see that line 444 use tstrncpy, so doing the same on 439 shouldn't be a problem.

One should perhaps also replace all those sprintf calls with calls to snprintf.

Dwachs

Parsley, sage, rosemary, and maggikraut.