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

locale.c usage of strxfrm

Thread Next
From:
Devin Heitmueller
Date:
April 20, 2007 15:20
Subject:
locale.c usage of strxfrm
Message ID:
412bdbff0704201520i7aac0189n74f0cef5c5213f41@mail.gmail.com
I am debugging a win32 core dump in locale.c, and noticed the usage
for strxfrm() in Perl_mem_collxfrm() does not appear to be correct.

Here's the relevant snippet:

	SSize_t xused;

	for (;;) {
	    xused = strxfrm(xbuf + xout, s + xin, xAlloc - xout);
	    if (xused == -1)
		goto bad;
	    if ((STRLEN)xused < xAlloc - xout)
		break;
	    xAlloc = (2 * xAlloc) + 1;
	    Renew(xbuf, xAlloc, char);
	    if (! xbuf)
		goto bad;
	}

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?

-- 
Devin J. Heitmueller
http://www.devinheitmueller.com
AIM: devinheitmueller

Thread Next


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