Hi,
في ث، 19-10-2010 عند 15:19 -0500 ، كتب Travis Beaty:
> Hello everyone.
>
> I am working on a little test code to learn Vala. I am getting the
> following warning from compiler:
>
> /home/.../ValaTest.vala.c: In function
> ‘vala_test_vala_test_delete_event_this’:
>
> /home/.../ValaTest.vala.c:129: warning: format not a string literal and
> no format arguments
This warning comes from the C compiler. These can usually be safely
ignored (but see below).
> Here is the method I feel is responsible for this:
>
>
> private bool delete_event_this() {
>
> var msg = new MessageDialog(this, DialogFlags.MODAL,
> MessageType.INFO, ButtonsType.OK,
> "I've been clicked " + clicks.to_string() + " times!");
> msg.run();
>
> stdout.printf("I was clicked " + clicks.to_string() + " times!\n");
The warning is caused by this line ^^
you are passing a non-constant string to printf, this is potentially a
security risk (e.g. if your string is constructed from user input).
The normal use of printf is to pass a constant string format, and
arguments (assuming clicks is an int):
stdout.printf("I was clicked %d times!\n", clicks);
If you prefer constructing your string by using concatenation, you can
still use puts instead of printf.
And a last tip : a nicer way to do the convertion to string and the
concatenation is to use string templates (with the leading @):
@"I was clicked $clicked times"
HTH,
Abderrahim
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list