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

Re: locale.c usage of strxfrm

Thread Previous
From:
Rafael Garcia-Suarez
Date:
April 26, 2007 09:59
Subject:
Re: locale.c usage of strxfrm
Message ID:
b77c1dce0704260959i47d3077fx746b5bb6828d681d@mail.gmail.com
On 21/04/07, Devin Heitmueller <devin.heitmueller@gmail.com> 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" <devin.heitmueller@gmail.com>
        Date: Fri, 20 Apr 2007 18:20:21 -0400
        Message-ID:
<412bdbff0704201520i7aac0189n74f0cef5c5213f41@mail.gmail.com>

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)
                break;

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About