develooper Front page | perl.perl5.porters | Postings from April 2007

Re: locale.c usage of strxfrm

Thread Previous
Rafael Garcia-Suarez
April 26, 2007 09:59
Re: locale.c usage of strxfrm
Message ID:
On 21/04/07, Devin Heitmueller <> wrote:
> So xused is an SSize_t, which on Win32 is a signed int and on linux is
> a ssize_t (also effectively an signed int).  However, if I look at
> both the man page and the MSDN documentation for strxfrm(), they both
> have an expected return type of size_t (an unsigned int on most
> platforms).
> Now the behavior that occurs on error is not well documented in the
> Linux man page, but the MSDN document claims that INT_MAX is returned
> on error.  This is consistent with the Linux interface which indicates
> that an error has occurred if the return value is greater than the
> third argument.
> In my failure case on Win32, the return value is INT_MAX (2147483647).
>  However, the code checks for the result being equal to -1.  Does it
> make sense for xused to be a Size_t instead of a SSize_t?  Should the
> check really be for -1, or perhaps INT_MAX makes more sense?  Are
> there other platforms where the return for strxfrm is not a size_t?

Indeed, a Size_t makes more sense here. However, a UINT_MAX would make
more sense too. But as you say that INT_MAX is read in the docs, I've
applied the following patch. (BTW, the FreeBSD manpage is not clearer
than the Linux one...)

Change 31092 by rgs@stcosmo on 2007/04/26 16:57:55

        strxfrm() returns a size_t, not a ssize_t. See:

        Subject: locale.c usage of strxfrm
        From: "Devin Heitmueller" <>
        Date: Fri, 20 Apr 2007 18:20:21 -0400

Affected files ...

... //depot/perl/locale.c#38 edit

Differences ...

==== //depot/perl/locale.c#38 (text) ====

@@ -588,11 +588,11 @@
     *(U32*)xbuf = PL_collation_ix;
     xout = sizeof(PL_collation_ix);
     for (xin = 0; xin < len; ) {
-       SSize_t xused;
+       Size_t xused;

        for (;;) {
            xused = strxfrm(xbuf + xout, s + xin, xAlloc - xout);
-           if (xused == -1)
+           if (xused >= PERL_INT_MAX)
                goto bad;
            if ((STRLEN)xused < xAlloc - xout)

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About