Bug 41071 - glib should handle positional parameters(%n$)
Summary: glib should handle positional parameters(%n$)
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glib
Version: 7.1
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Owen Taylor
QA Contact: Aaron Brown
Depends On:
TreeView+ depends on / blocked
Reported: 2001-05-17 07:07 UTC by Nakai
Modified: 2007-03-27 03:44 UTC (History)
4 users (show)

Clone Of:
Last Closed: 2003-01-14 00:46:48 UTC

Attachments (Terms of Use)
a code to crash. (198 bytes, patch)
2001-05-23 08:15 UTC, Nakai
no flags Details | Diff
And this is a simple patch for glib. (431 bytes, patch)
2001-05-23 08:18 UTC, Nakai
no flags Details | Diff

Description Nakai 2001-05-17 07:07:44 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.72 [muriyari-ja] (X11; U; Linux 2.2.14-5.0 i686)

Description of problem:

How reproducible:

Steps to Reproduce:
1. Run gnumeric in Japanese environment(LANG=ja_JP.eucJP)
2. Insert a columun.

Actual Results:  SIGSEGV

Expected Results:  Insert the column.

Additional info:

ja.po in gnumeric says(write Japanese part in alphabet):

#: src/commands.c:928
#, c-format
msgid "Inserting %d column before %s"
msgstr "%2$s no maeni %1$d retsu wo sounyuu"

but glib doesn't support %2$s type so gnumeric crashes.
glib should support this. See 871 line in glib-1.2.9/gstrfuncs.c

Comment 1 Nakai 2001-05-17 07:08:51 UTC
This bug also occurs on the gnumeric in the Korean

Comment 2 Nakai 2001-05-17 07:36:51 UTC
(Summary fix: not glibc but glib)

Comment 3 Owen Taylor 2001-05-17 14:08:28 UTC
This is _extremely_ hard to do. Basically, to do it portably, you
either have to:

 - Ship a complete printf() implementation with GLib to be
   used on systems where stdio doesn't support positional
   parameters. Since handling things like float formatting
   is highly non-trivial, I'd be quite reluctant to do this.
 - Know how to portably rewrite valists when passing
   them to vsprintf().

At some point in the future, we may just require a C library
with support for positional parameters.  However, since positional
parameters are NOT part of ISO C99, though they are part
of SUSv2, and we do care about portability to non-Unix systems
now, I don't imagine we'll be doing this any time soon.

For now it should be just be treated as a limitation in GLib. :-(

Comment 4 Nakai 2001-05-18 07:50:23 UTC
g_printf_string_upper_bound() just returns the total length.

If glib doesn't support this, I want another idea of replacement.
Many developer will use this.

Comment 5 Owen Taylor 2001-05-18 12:57:38 UTC
It's easy to make it work on Red Hat, on Linux, on modern Unix.

However, then .po files that work on Linux, will suddenly not
work and most likely segfault on other operating systems.

Since the translations we make should always be sent upstream 
to the original package maintainers, and since most of
the packages we ship that use GLib are not Linux specific,
I don't see that adding positional parameters to g_strdup_sprintf(),
has significant value.

Comment 6 Nakai 2001-05-23 08:15:30 UTC
Created attachment 19371 [details]
a code to crash.

Comment 7 Nakai 2001-05-23 08:18:01 UTC
Attached is a code to crash with glib.
I think it is very silly that it crashes in a function that just
returns the length.

Comment 8 Nakai 2001-05-23 08:18:54 UTC
Created attachment 19372 [details]
And this is a simple patch for glib.

Comment 9 Owen Taylor 2001-05-23 14:56:29 UTC
Agreed, it would be better to skip the entire format specifier
after warning.

(Note that the patch above doesn't seem to handle things like

I've filed this as:


Comment 10 Nakai 2002-03-27 06:38:11 UTC
Is this fixed for Hampton?

Comment 11 Owen Taylor 2002-03-27 16:04:51 UTC
GLib-1.2 behaves as you did before ... you can't use positional parameters.
GLib-2.0 has some changes so that (on sufficiently modern Unix-like systems)
you can use whatever capabilities the native printf has.

Comment 12 Owen Taylor 2003-01-14 00:46:48 UTC
Not going to do anything on glib-1.2 at this point. In Glib-2.2, Glib
will always provide positional parameter support; if the C library
doesn't support it, it includes a copy of the 'trio' library.

Note You need to log in before you can comment on or make changes to this bug.