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

locale.c usage of strxfrm

Thread Next
Devin Heitmueller
April 20, 2007 15:20
locale.c usage of strxfrm
Message ID:
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)
	    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

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
AIM: devinheitmueller

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