Skip to contentSkip to conversation

Build failures on Ubuntu due to gettext

PATCH Colin Watson 4 participants 22 messages Dec 7, 2009 – Dec 11, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

Ubuntu's GCC enables -Wformat-security by default. This causes GCC to (IMO rightly!) complain about constructs such as this:

  grub_printf (_("foo"));

... because it's all too easy for a translator to (usually accidentally) insert % sequences which would cause printf to behave incorrectly. This should instead be:

  grub_printf ("%s", _("foo"));

Patch follows. I can't help thinking that this would be easier with a grub_puts, but perhaps that isn't worth it given the relatively small number of occurrences here?

Also, should the line in notify_execution_failure instead be:

- grub_printf (_("Failed to boot default entries.\n"));
+ grub_printf ("%s\n", _("Failed to boot default entries."));

... to get rid of the unsightly \n in this translated string?

2009-12-07 Colin Watson <[email protected]>

* normal/menu_entry.c (run): Don't pass the result of gettext as the first argument to grub_printf, appeasing -Wformat-security. (grub_menu_entry_run): Likewise.
* normal/menu_text.c (grub_wait_after_message): Likewise. (print_message): Likewise. (notify_execution_failure): Likewise.

=== modified file 'normal/menu_entry.c'

menu_entry.c +2 -2
@@ -1000,7 +1000,7 @@ run (struct screen *screen)
 
   grub_cls ();
   grub_printf ("  ");
-  grub_printf (_("Booting a command list"));
+  grub_printf ("%s", _("Booting a command list"));
   grub_printf ("\n\n");
 
 
@@ -1182,6 +1182,6 @@ grub_menu_entry_run (grub_menu_entry_t e
   grub_print_error ();
   grub_errno = GRUB_ERR_NONE;
   grub_putchar ('\n');
-  grub_printf (_("Press any key to continue..."));
+  grub_printf ("%s", _("Press any key to continue..."));
   (void) grub_getkey ();
 }

=== modified file 'normal/menu_text.c'

menu_text.c +3 -3
@@ -40,7 +40,7 @@ void
 grub_wait_after_message (void)
 {
   grub_putchar ('\n');
-  grub_printf (_("Press any key to continue..."));
+  grub_printf ("%s", _("Press any key to continue..."));
   (void) grub_getkey ();
   grub_putchar ('\n');
 }
@@ -206,7 +206,7 @@ entry is highlighted.");
       if (nested)
         {
           grub_printf ("\n        ");
-          grub_printf (_("ESC to return previous menu."));
+          grub_printf ("%s", _("ESC to return previous menu."));
         }
     }
 }
@@ -655,7 +655,7 @@ notify_execution_failure (void *userdata
       grub_errno = GRUB_ERR_NONE;
     }
   grub_printf ("\n  ");
-  grub_printf (_("Failed to boot default entries.\n"));
+  grub_printf ("%s", _("Failed to boot default entries.\n"));
   grub_wait_after_message ();
 }
 

Thanks,

Signature · 1 line
Colin Watson                                       [[email protected]]
#1 lore raw

Hello,

Quoted 4 lines · Colin Watson

Ubuntu's GCC enables -Wformat-security by default. This causes GCC to (IMO rightly!) complain about constructs such as this:

  grub_printf (_("foo"));

I see...
(actually some weeks ago I thought about gettext security implications, and I thought that if someone can change the .mo files there is some bigger problem for the user... but I understand the point)

Quoted 2 lines

... because it's all too easy for a translator to (usually accidentally) insert % sequences which would cause printf to behave

(side and non-relevant note: if the translator wants to do some damage on purpose he doesn't need to play with %s and %d, it's as easy as changing strings from "Press C to Cancel and D to delete" to something like (in another language) "Press D to Cancel and C to delete")

Quoted 3 lines

incorrectly. This should instead be:

  grub_printf ("%s", _("foo"));

I like the general idea but I'm not 100% convinced of the implementation:

a) It's a bit of false security because it's not fixing the case of file normal/menu_text.c, line 191 (search the string "Use the %C and %C keys to") or menu_text.c line 374 (search for "The highlighted entry") (I agree that it's better than before... but not very solid)

b) How would you translate and handle:
grub_printf (_("Hello %s"), name);

The translator really needs "%s" because in other languages can be "%s hello" (not the best example but maybe you get the point)

c) I'm thinking to implement grub_printf_ (str). I will send a patch later to see if everybody likes. Then the call for simple strings would be:
grub_printf_ ("%s", N_("Hello"));

Not much different from:
grub_printf_ (N_("Hello"));

But it's getting hard to print a string :-)

d) (important, even if it's the last one):
How it prevents mistakes from the current msgfmt checks? For example, and using the option -c in msgfmt:
#: normal/misc.c:67
#, c-format
msgid "test %s t"
msgstr "test %d test2"

/usr/bin/msgfmt -c --statistics -o po/ca.mo po/ca.po po/ca.po:1183: format specifications in 'msgid' and 'msgstr' for argument 1 are not the same
/usr/bin/msgfmt: found 1 fatal error
26 translated messages, 213 untranslated messages.

Using any different number of %X from msgid and msgstr ishalting msgfmt (so, if msgid contains 1 %s and 2 %d, msgstr has to contain the same)

We are talking from _(" "), I see that -Wformat-security is for "string came from untrusted input and contains" when .mo are trusted. Are they?

How are other projectes implementing it? Specially the dynamic strings.

Quoted 3 lines

Patch follows. I can't help thinking that this would be easier with a grub_puts, but perhaps that isn't worth it given the relatively small number of occurrences here?

We could replace grub_puts with grub_printf... or some other idea.

Quoted 6 lines

Also, should the line in notify_execution_failure instead be:

(quoted diff) +1 -1
-  grub_printf (_("Failed to boot default entries.\n"));
+  grub_printf ("%s\n", _("Failed to boot default entries."));

... to get rid of the unsightly \n in this translated string?

I really like that this fix the \n discussion that we had :-)

I like the idea and I understand that it's easy to make mistakes translating strings. Actually I'm surprised that msgfmt is not giving any warning if the

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info
#2 lore raw
Quoted 23 lines · Carles Pina i Estany
Quoted 4 lines · Colin Watson

Ubuntu's GCC enables -Wformat-security by default. This causes GCC to (IMO rightly!) complain about constructs such as this:

  grub_printf (_("foo"));

I see...
(actually some weeks ago I thought about gettext security implications, and I thought that if someone can change the .mo files there is some bigger problem for the user... but I understand the point)

Quoted 2 lines

... because it's all too easy for a translator to (usually accidentally) insert % sequences which would cause printf to behave

(side and non-relevant note: if the translator wants to do some damage on purpose he doesn't need to play with %s and %d, it's as easy as changing strings from "Press C to Cancel and D to delete" to something like (in another language) "Press D to Cancel and C to delete")

Quoted 3 lines

incorrectly. This should instead be:

  grub_printf ("%s", _("foo"));
Quoted 7 lines

I like the general idea but I'm not 100% convinced of the implementation:

a) It's a bit of false security because it's not fixing the case of file normal/menu_text.c, line 191 (search the string "Use the %C and %C keys to") or menu_text.c line 374 (search for "The highlighted entry") (I agree that it's better than before... but not very solid)

Forget security, in this case; let's just think of it as a way to avoid translators accidentally shooting themselves (and their users) in the foot. I have seen this happen and it's best to prevent it by static checking.

Quoted 2 lines

b) How would you translate and handle:
grub_printf (_("Hello %s"), name);

-Wformat-security doesn't interfere with that. As its documentation says:

At present, this warns about calls to printf' and scanf' functions where the format string is not a string literal and there are no format arguments, as in `printf (foo);'.

Quoted 9 lines

c) I'm thinking to implement grub_printf_ (str). I will send a patch later to see if everybody likes. Then the call for simple strings would be:
grub_printf_ ("%s", N_("Hello"));

Not much different from:
grub_printf_ (N_("Hello"));

But it's getting hard to print a string :-)

grub_puts would be nice and would match the POSIX API (or maybe grub_fputs or grub_putstr or something, since POSIX puts is kind of odd in writing a trailing newline).

I don't really like significant trailing underscores in function names myself, although I see why you chose it here.

Quoted 8 lines

d) (important, even if it's the last one):
How it prevents mistakes from the current msgfmt checks? For example, and using the option -c in msgfmt:
#: normal/misc.c:67
#, c-format
msgid "test %s t"
msgstr "test %d test2"

Quoted 8 lines

/usr/bin/msgfmt -c --statistics -o po/ca.mo po/ca.po po/ca.po:1183: format specifications in 'msgid' and 'msgstr' for argument 1 are not the same
/usr/bin/msgfmt: found 1 fatal error
26 translated messages, 213 untranslated messages.

Using any different number of %X from msgid and msgstr ishalting msgfmt (so, if msgid contains 1 %s and 2 %d, msgstr has to contain the same)

That only works for strings with the "c-format" attribute, which xgettext only applies (and should only apply) to msgids that contain "%". It helps for the string you mentioned earlier with %C in the msgid, but it's no use for _("literal string with no percent characters").

Quoted 2 lines

We are talking from _(" "), I see that -Wformat-security is for "string came from untrusted input and contains" when .mo are trusted. Are they?

I would recommend against considering .mo as entirely trusted, unless you really think that developers will read every submission line-by-line. I realise that as you say there are plenty of more subtle avenues of attack; as I said above, I really think of this as foot-shooting prevention more than security.

Quoted 1 line

How are other projectes implementing it? Specially the dynamic strings.

Every competent project I've seen that uses gettext in C is in line with the patch I sent, although some use an equivalent of printf("%s", ...) while some use an equivalent of fputs(..., stdout).

Quoted 3 lines

I like the idea and I understand that it's easy to make mistakes translating strings. Actually I'm surprised that msgfmt is not giving any warning if the

In general it can only do this for appropriately tagged strings. For an arbitrary literal string it often isn't actually wrong to translate it with text containing a "%" sign - it's just that it crashes the program. Thus, it's the program's responsibility to avoid crashing.

Signature · 1 line
Colin Watson                                       [[email protected]]
#3 lore raw

Hi,

Quoted 8 lines · Colin Watson
Quoted 4 lines · Carles Pina i Estany

a) It's a bit of false security because it's not fixing the case of file normal/menu_text.c, line 191 (search the string "Use the %C and %C keys to") or menu_text.c line 374 (search for "The highlighted entry") (I agree that it's better than before... but not very solid)

Forget security, in this case; let's just think of it as a way to avoid

Ok, I'll forget about security (even when the name is not helping to forget about security :-) )

Quoted 9 lines
Quoted 2 lines

b) How would you translate and handle:
grub_printf (_("Hello %s"), name);

-Wformat-security doesn't interfere with that. As its documentation says:

At present, this warns about calls to printf' and scanf' functions where the format string is not a string literal and there are no format arguments, as in `printf (foo);'.

I see now (not before)

Quoted 7 lines
Quoted 3 lines

Using any different number of %X from msgid and msgstr ishalting msgfmt (so, if msgid contains 1 %s and 2 %d, msgstr has to contain the same)

That only works for strings with the "c-format" attribute, which xgettext only applies (and should only apply) to msgids that contain "%". It helps for the string you mentioned earlier with %C in the msgid,

right. Actually I was expecting that all strings in a C file would has c-format, but it's not the case:
----
#: normal/menu_entry.c:840
#, c-format
msgid "Possible %s are:"

#: normal/menu_entry.c:1003
msgid "Booting a command list"
----

And confirmed: if the translator adds %C in the second string ("Booting a command list") msgfmt -c is not complaining.

So I would apply your patch, after understanding that it's only for strings that doesn't have any %C (and in my opinion xgettext could add the c-format if it's in a C file, but we will not discuss it here now :-) , I guess that in some cases would not be correct)

Your patch conflicts with my one (Subject: gettext: grub_printf_ and N_) but it's not a big problem. If you commit before I would adapt my one, else I would adapt your one.

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info
#4 lore raw
Quoted 13 lines · Carles Pina i Estany

And confirmed: if the translator adds %C in the second string ("Booting a command list") msgfmt -c is not complaining.

So I would apply your patch, after understanding that it's only for strings that doesn't have any %C (and in my opinion xgettext could add the c-format if it's in a C file, but we will not discuss it here now :-) , I guess that in some cases would not be correct)

Your patch conflicts with my one (Subject: gettext: grub_printf_ and N_) but it's not a big problem. If you commit before I would adapt my one, else I would adapt your one.

Your N_ patch superseeds Colin's patch. Feel free to use printf_ where necessary. It solves format-security problems

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#5 lore raw
Quoted 2 lines · Vladimir 'φ-coder/phcoder' Serbinenko

Your N_ patch superseeds Colin's patch. Feel free to use printf_ where necessary. It solves format-security problems

It only works around the compiler warning if functions have not been given the correct function attributes. It certainly doesn't solve the underlying issue.

Signature · 1 line
Colin Watson                                       [[email protected]]
#6 lore raw
In reply to Carles Pina i Estany

Hi,

Quoted 1 line · Carles Pina i Estany

So I would apply your patch, after understanding that it's only for

one more thing Colin. What do you think to not apply your patch and apply the attached patch?

It force that the argument 1 of _ and N_ is a c-format (in this way appears in grub.pot). This is, IMO, correct approach. And then msgfmt -c checks the number of arguments.

If other projects are not using this approach they could have some reason, like _("File") is a menu label and not a C format string. In this cases, if this happens in Grub it's not making things worse.

Using it we should have all checks about the number of arguments and we are not programming warning oriented.

If it's a linguism and wide accepted to do in the other way I personally don't have any strong objection.

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info

=== modified file 'Makefile.in'

Makefile.in +1 -1
@@ -477,7 +477,7 @@ genkernsyms.sh: genkernsyms.sh.in config
 	$(SHELL) ./config.status
 
 $(srcdir)/po/$(PACKAGE).pot: po/POTFILES po/POTFILES-shell
-	cd $(srcdir) && $(XGETTEXT) --from-code=utf-8 -o $@ -f $< --keyword=_ --keyword=N_
+	cd $(srcdir) && $(XGETTEXT) --from-code=utf-8 -o $@ -f $< --keyword=_ --keyword=N_ --flag=N_:1:c-format --flag=_:1:c-format
 	cd $(srcdir) && $(XGETTEXT) --from-code=utf-8 -o $@ -f po/POTFILES-shell -j --language=Shell
 
 $(foreach lang, $(LINGUAS), $(srcdir)/po/$(lang).po): po/$(PACKAGE).pot
#7 lore raw
Quoted 9 lines · Carles Pina i Estany
Quoted 1 line · Carles Pina i Estany

So I would apply your patch, after understanding that it's only for

one more thing Colin. What do you think to not apply your patch and apply the attached patch?

It force that the argument 1 of _ and N_ is a c-format (in this way appears in grub.pot). This is, IMO, correct approach. And then msgfmt -c checks the number of arguments.

I really think that this is incorrect, I'm afraid. I've certainly never seen any other project do this. There's no reason to restrict _ and N_ only to be used by printf-a-likes.

Cheers,

Signature · 1 line
Colin Watson                                       [[email protected]]
#8 lore raw
In reply to Carles Pina i Estany
Quoted 3 lines · Carles Pina i Estany

Your patch conflicts with my one (Subject: gettext: grub_printf_ and N_) but it's not a big problem. If you commit before I would adapt my one, else I would adapt your one.

Please go ahead with your patch after due discussion, and I'll adjust mine afterwards. It's too confusing to try to discuss both at the same time.

Signature · 1 line
Colin Watson                                       [[email protected]]
#9 lore raw

Hi,

Quoted 8 lines · Colin Watson
Quoted 3 lines · Carles Pina i Estany

Your patch conflicts with my one (Subject: gettext: grub_printf_ and N_) but it's not a big problem. If you commit before I would adapt my one, else I would adapt your one.

Please go ahead with your patch after due discussion, and I'll adjust mine afterwards. It's too confusing to try to discuss both at the same time.

I just pushed my one since I understand that it's all right (using grub_vprintf). And it's complementary with your one.

If you push your one (for which one I agree) I will adjust my pending patches to follow the coding sytle.

Thanks,

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info
#10 lore raw
In reply to Colin Watson
Quoted 20 lines · Colin Watson

Ubuntu's GCC enables -Wformat-security by default. This causes GCC to (IMO rightly!) complain about constructs such as this:

  grub_printf (_("foo"));

... because it's all too easy for a translator to (usually accidentally) insert % sequences which would cause printf to behave incorrectly. This should instead be:

  grub_printf ("%s", _("foo"));

Patch follows. I can't help thinking that this would be easier with a grub_puts, but perhaps that isn't worth it given the relatively small number of occurrences here?

Also, should the line in notify_execution_failure instead be:

(quoted diff) +1 -1
-  grub_printf (_("Failed to boot default entries.\n"));
+  grub_printf ("%s\n", _("Failed to boot default entries."));
Quoted 2 lines

... to get rid of the unsightly \n in this translated string?

This warning is simply wrong in this context. And silencing it is against gettext manual. Read
http://www.gnu.org/software/hello/manual/gettext/Preparing-Strings.html
http://www.gnu.org/software/hello/manual/gettext/c_002dformat-Flag.html#c_002dformat-Flag

Quoted 64 lines

2009-12-07 Colin Watson <[email protected]>

* normal/menu_entry.c (run): Don't pass the result of gettext as the first argument to grub_printf, appeasing -Wformat-security. (grub_menu_entry_run): Likewise.
* normal/menu_text.c (grub_wait_after_message): Likewise. (print_message): Likewise. (notify_execution_failure): Likewise.

=== modified file 'normal/menu_entry.c'

menu_entry.c +2 -2
@@ -1000,7 +1000,7 @@ run (struct screen *screen)
 
   grub_cls ();
   grub_printf ("  ");
-  grub_printf (_("Booting a command list"));
+  grub_printf ("%s", _("Booting a command list"));
   grub_printf ("\n\n");
 
 
@@ -1182,6 +1182,6 @@ grub_menu_entry_run (grub_menu_entry_t e
   grub_print_error ();
   grub_errno = GRUB_ERR_NONE;
   grub_putchar ('\n');
-  grub_printf (_("Press any key to continue..."));
+  grub_printf ("%s", _("Press any key to continue..."));
   (void) grub_getkey ();
 }

=== modified file 'normal/menu_text.c'

menu_text.c +3 -3
@@ -40,7 +40,7 @@ void
 grub_wait_after_message (void)
 {
   grub_putchar ('\n');
-  grub_printf (_("Press any key to continue..."));
+  grub_printf ("%s", _("Press any key to continue..."));
   (void) grub_getkey ();
   grub_putchar ('\n');
 }
@@ -206,7 +206,7 @@ entry is highlighted.");
       if (nested)
         {
           grub_printf ("\n        ");
-          grub_printf (_("ESC to return previous menu."));
+          grub_printf ("%s", _("ESC to return previous menu."));
         }
     }
 }
@@ -655,7 +655,7 @@ notify_execution_failure (void *userdata
       grub_errno = GRUB_ERR_NONE;
     }
   grub_printf ("\n  ");
-  grub_printf (_("Failed to boot default entries.\n"));
+  grub_printf ("%s", _("Failed to boot default entries.\n"));
   grub_wait_after_message ();
 }
 

Thanks,

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#11 lore raw
Quoted 16 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 15 lines · Colin Watson

Ubuntu's GCC enables -Wformat-security by default. This causes GCC to (IMO rightly!) complain about constructs such as this:

  grub_printf (_("foo"));

... because it's all too easy for a translator to (usually accidentally) insert % sequences which would cause printf to behave incorrectly. This should instead be:

  grub_printf ("%s", _("foo"));

Patch follows. I can't help thinking that this would be easier with a grub_puts, but perhaps that isn't worth it given the relatively small number of occurrences here?

Quoted 8 lines
Quoted 6 lines

Also, should the line in notify_execution_failure instead be:

(quoted diff) +1 -1
-  grub_printf (_("Failed to boot default entries.\n"));
+  grub_printf ("%s\n", _("Failed to boot default entries."));

... to get rid of the unsightly \n in this translated string?

This warning is simply wrong in this context.

I disagree. I have seen many practical problems caused by this coding style.

Quoted 2 lines

And silencing it is against gettext manual. Read
http://www.gnu.org/software/hello/manual/gettext/Preparing-Strings.html

I see nothing relevant in that link. (I am familiar with gettext already, having been using it for many years in other free software projects.)

Quoted 1 line

http://www.gnu.org/software/hello/manual/gettext/c_002dformat-Flag.html#c_002dformat-Flag

That suggests one available option for tweaking the way gettext handles such strings, but it does not prescribe any particular solution to the problem. Indeed, it says "Of course one would normally use fputs", which is just as valid a solution as adding the c-format flag, and quite possibly more valid since it's a heck of a lot easier to maintain. We don't have fputs in GRUB right now, so grub_printf ("%s", _(...)) is perfectly valid too, in just the same way that fputs is.

IME, forcing no-c-format is much more useful than forcing c-format.

In short, it is not true that "silencing it is against gettext manual", but thank you for providing me with links that if anything support my position. ;-)

Vladimir, please can you be a little less terse in your objections in future? For example, it is often helpful to quote specific text rather than vague URLs. If you would like arbitration on whether my approach is "correct" as per the gettext maintainers, I'm happy to bring it up with them.

Thanks,

Signature · 1 line
Colin Watson                                       [[email protected]]
#12 lore raw

Furthermore, the style I suggested is used in many other GNU projects. Here are just a few examples:

  coreutils/src/du.c:994:       error (0, 0, "%s", _("invalid zero-length file name"));
  diffutils/src/sdiff.c:853:  fprintf (stderr, "%s", _("\
  diffutils/src/sdiff.c-854-ed:\tEdit then use both versions, each decorated with a header.\n\
  glibc/inet/rcmd.c:178:                              __fxprintf(NULL, "%s", _("\
  glibc/inet/rcmd.c-179-rcmd: socket: All ports in use\n"));
  gnulib/lib/xalloc-die.c:34:  error (exit_failure, 0, "%s", _("memory exhausted"));

Indeed, here's a commit from the gettext author using this style:

http://git.savannah.gnu.org/cgit/gettext.git/commit/?id=d5d1ae3b3c3ae2f837740e5f5d65326197ccdb98

(Look for close_stdout_status in lib/closeout.c.)

Signature · 1 line
Colin Watson                                       [[email protected]]
#13 lore raw
Quoted 11 lines · Colin Watson

Furthermore, the style I suggested is used in many other GNU projects. Here are just a few examples:

  coreutils/src/du.c:994:       error (0, 0, "%s", _("invalid zero-length file name"));
  diffutils/src/sdiff.c:853:  fprintf (stderr, "%s", _("\
  diffutils/src/sdiff.c-854-ed:\tEdit then use both versions, each decorated with a header.\n\
  glibc/inet/rcmd.c:178:                              __fxprintf(NULL, "%s", _("\
  glibc/inet/rcmd.c-179-rcmd: socket: All ports in use\n"));
  gnulib/lib/xalloc-die.c:34:  error (exit_failure, 0, "%s", _("memory exhausted"));

I have nothing against defining grub_putl_ (str); equivalent to grub_printf ("%s\n", str); (defined as function if it's used extensively for space reasons).
Just from your previous mails it seemed that you proposed to transform strings like
grub_printf (_("Moving file %s to %s."), f1, f2); to grub_printf ("%s %s %s %s.", _("Moving file"), f1, _("to"), f2);
to avoid translating format-strings which would be completely untranslatable.

Quoted 7 lines

Indeed, here's a commit from the gettext author using this style:

http://git.savannah.gnu.org/cgit/gettext.git/commit/?id=d5d1ae3b3c3ae2f837740e5f5d65326197ccdb98

(Look for close_stdout_status in lib/closeout.c.)

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#14 lore raw
Quoted 11 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 9 lines · Colin Watson

Furthermore, the style I suggested is used in many other GNU projects. Here are just a few examples:

  coreutils/src/du.c:994:       error (0, 0, "%s", _("invalid zero-length file name"));
  diffutils/src/sdiff.c:853:  fprintf (stderr, "%s", _("\
  diffutils/src/sdiff.c-854-ed:\tEdit then use both versions, each decorated with a header.\n\
  glibc/inet/rcmd.c:178:                              __fxprintf(NULL, "%s", _("\
  glibc/inet/rcmd.c-179-rcmd: socket: All ports in use\n"));
  gnulib/lib/xalloc-die.c:34:  error (exit_failure, 0, "%s", _("memory exhausted"));
Quoted 9 lines

I have nothing against defining grub_putl_ (str); equivalent to grub_printf ("%s\n", str); (defined as function if it's used extensively for space reasons).
Just from your previous mails it seemed that you proposed to transform strings like
grub_printf (_("Moving file %s to %s."), f1, f2); to grub_printf ("%s %s %s %s.", _("Moving file"), f1, _("to"), f2);
to avoid translating format-strings which would be completely untranslatable.

What on earth?! I said nothing of the kind! That would obviously be completely insane. How did you arrive at that impression?

My patch made the following transformation:

- grub_printf (_("literal string"));
+ grub_printf ("%s", _("literal string"));

This was only necessary in five places, so I doubt that a function is worth it.

Thanks,

Signature · 1 line
Colin Watson                                       [[email protected]]
#15 lore raw
Quoted 2 lines · Colin Watson

What on earth?! I said nothing of the kind! That would obviously be completely insane.

Sorry for having misunderstood you.

Quoted 2 lines

How did you arrive at that impression?

Extrapolation of proposed changes since a lot of patches in gettext threads were "samples".

Quoted 8 lines

My patch made the following transformation:

(quoted diff) +1 -1
-  grub_printf (_("literal string"));
+  grub_printf ("%s", _("literal string"));

This was only necessary in five places, so I doubt that a function is worth it.

Then it's not worth it. But again we haven't gettext'ized whole grub2 yet to know for sure. Perhaps a macro so we can change it later if necessary?

Quoted 3 lines

Thanks,

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#16 lore raw

Hi Vladimir, Colin,

Quoted 11 lines · Vladimir '??-coder/phcoder' Serbinenko
Quoted 8 lines

My patch made the following transformation:

(quoted diff) +1 -1
-  grub_printf (_("literal string"));
+  grub_printf ("%s", _("literal string"));

This was only necessary in five places, so I doubt that a function is worth it.

Then it's not worth it. But again we haven't gettext'ized whole grub2 yet to know for sure. Perhaps a macro so we can change it later if necessary?

Vladimir, Colin: see the attached patch with the Colin changes but macrofied.

Should compile fine in Ubuntu, but I have not tried.

Are we happy with grub_put_ function name?

Colin: could you apply this patch or similar?

I don't want to push more gettext strings before setting up the basic infrastructure to avoid working twice.

Thanks,

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info

=== modified file 'include/grub/misc.h'

grub/misc.h +2 -0
@@ -34,6 +34,8 @@
 /* XXX: If grub_memmove is too slow, we must implement grub_memcpy.  */
 #define grub_memcpy(d,s,n)	grub_memmove ((d), (s), (n))
 
+#define grub_put_(str)		grub_printf("%s", (str))
+
 void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n);
 char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src);
 char *EXPORT_FUNC(grub_strncpy) (char *dest, const char *src, int c);

=== modified file 'normal/menu_entry.c'

menu_entry.c +2 -2
@@ -1000,7 +1000,7 @@ run (struct screen *screen)
 
   grub_cls ();
   grub_printf ("  ");
-  grub_printf_ (N_("Booting a command list"));
+  grub_put_ (N_("Booting a command list"));
   grub_printf ("\n\n");
 
 
@@ -1182,6 +1182,6 @@ grub_menu_entry_run (grub_menu_entry_t e
   grub_print_error ();
   grub_errno = GRUB_ERR_NONE;
   grub_putchar ('\n');
-  grub_printf_ (N_("Press any key to continue..."));
+  grub_put_ (N_("Press any key to continue..."));
   (void) grub_getkey ();
 }

=== modified file 'normal/menu_text.c'

menu_text.c +3 -3
@@ -40,7 +40,7 @@ void
 grub_wait_after_message (void)
 {
   grub_putchar ('\n');
-  grub_printf_ (N_("Press any key to continue..."));
+  grub_put_ (N_("Press any key to continue..."));
   (void) grub_getkey ();
   grub_putchar ('\n');
 }
@@ -206,7 +206,7 @@ entry is highlighted.");
       if (nested)
         {
           grub_printf ("\n        ");
-          grub_printf_ (N_("ESC to return previous menu."));
+          grub_put_ (N_("ESC to return previous menu."));
         }
     }
 }
@@ -655,7 +655,7 @@ notify_execution_failure (void *userdata
       grub_errno = GRUB_ERR_NONE;
     }
   grub_printf ("\n  ");
-  grub_printf_ (N_("Failed to boot default entries.\n"));
+  grub_put_ (N_("Failed to boot default entries.\n"));
   grub_wait_after_message ();
 }
 
#17 lore raw

Hi,

As Vladimir spotted:

On Dec/09/2009, Carles Pina i Estany wrote:

This...:

Quoted 1 line

+#define grub_put_(str) grub_printf("%s", (str))

should be:
#define grub_put_(str) grub_printf(N_ ("%s"), (str))

If you Colin commit it don't propagate my mistake.

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info
#18 lore raw

Hi,

On Dec/10/2009, Carles Pina i Estany wrote:

As Richard commented (thanks):

Quoted 1 line

#define grub_put_(str) grub_printf(N_ ("%s"), (str))

#define grub_put_(str) grub_printf("%s", N (str))

I should not be sending patches when too tired / without properly testing with the .po that I've just deleted doing some other tests :-)

Now should be fine and after it's committed next gettext patches will use it when needed.

Cheers,

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info
#19 lore raw
In reply to Colin Watson
Quoted 8 lines · Colin Watson

My patch made the following transformation:

(quoted diff) +1 -1
-  grub_printf (_("literal string"));
+  grub_printf ("%s", _("literal string"));

This was only necessary in five places, so I doubt that a function is worth it.

I think we all agree that it's safer to avoid gettextizing the template; furthemore I agree with Colin that this seems to be a correct approach, but our case is unusual in that we're very pressed for size.

Even if we're only discussing a change in five places, I assume we're going to find this situation in lots of calls throurough GRUB code. If this is so, it really calls for a solution that doesn't make GCC generate two memory references and pass two arguments.

So first of all, how many times are we going to find similar calls that need to be adjusted in some way? If we're going to find many of them (as I expect), I think this warrants adding a new function (which, btw, will also make GRUB slightly faster).

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#20 lore raw

Hi,

Quoted 9 lines · Robert Millan

On Tue, Dec 08, 2009 at 12:10:34AM +0000, Colin Watson wrote:

Even if we're only discussing a change in five places, I assume we're going to find this situation in lots of calls throurough GRUB code. If this is so, it really calls for a solution that doesn't make GCC generate two memory references and pass two arguments.

So first of all, how many times are we going to find similar calls that

very rush numbers, based on my non-commited pending to improve patch to change commands/*:

carles@pinux:~/grub2/grub/po$ grep -A 3 "\#\: commands\/" grub.pot |
grep ^msgid | grep -c -v %
86
Quoted 3 lines

need to be adjusted in some way? If we're going to find many of them (as I expect), I think this warrants adding a new function (which, btw, will also make GRUB slightly faster).

Plus about 10 in normal/* (aprox, 5 that Colin did and some more in another pending patch I guess)

I haven't looked in other code yet.

I think that Vladimir proposed to do it in a macro now and then properly count and implement as a function or not later.

From: Vladimir
Date: Tue, 08 Dec 2009 01:15:30 +0100

Quoted 3 lines

Then it's not worth it. But again we haven't gettext'ized whole grub2 yet to know for sure. Perhaps a macro so we can change it later if necessary?

So, for about 86 in commands/* and probably some more in normal/*:
function now? Now a macro and then we review?

Colin: for me you can commit your patch some way or another so you could compile in Ubuntu and I can commit soon more things.

Thanks,

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info
#21 lore raw
In reply to Vladimir 'φ-coder/phcoder' Serbinenko

Hi,

Quoted 21 lines · Vladimir '??-coder/phcoder' Serbinenko
Quoted 20 lines · Colin Watson

Ubuntu's GCC enables -Wformat-security by default. This causes GCC to (IMO rightly!) complain about constructs such as this:

  grub_printf (_("foo"));

... because it's all too easy for a translator to (usually accidentally) insert % sequences which would cause printf to behave incorrectly. This should instead be:

  grub_printf ("%s", _("foo"));

Patch follows. I can't help thinking that this would be easier with a grub_puts, but perhaps that isn't worth it given the relatively small number of occurrences here?

Also, should the line in notify_execution_failure instead be:

(quoted diff) +1 -1
-  grub_printf (_("Failed to boot default entries.\n"));
+  grub_printf ("%s\n", _("Failed to boot default entries."));
Quoted 6 lines
Quoted 2 lines

... to get rid of the unsightly \n in this translated string?

This warning is simply wrong in this context. And silencing it is against gettext manual. Read
http://www.gnu.org/software/hello/manual/gettext/Preparing-Strings.html
http://www.gnu.org/software/hello/manual/gettext/c_002dformat-Flag.html#c_002dformat-Flag

other solution that I like even more (but I have a problem to implement): use --flag=_:1:pass-c-format . So all strings will be c-format and msgfmt will check the number of parameters (even if the string doesn't have %C, will be c-format and msgfmt should complain if msgstr has a new %C)

Signature · 2 lines
Carles Pina i Estany
	http://pinux.info