Unix Technical Forum

Re: Clear up strxfrm() in UTF-8 with locale on Windows

This is a discussion on Re: Clear up strxfrm() in UTF-8 with locale on Windows within the Pgsql Patches forums, part of the PostgreSQL category; --> Magnus Hagander <magnus@hagander.net> writes: > Given this, perhaps the proper approach should instead be to just check > the ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 10:00 AM
Tom Lane
 
Posts: n/a
Default Re: Clear up strxfrm() in UTF-8 with locale on Windows

Magnus Hagander <magnus@hagander.net> writes:
> Given this, perhaps the proper approach should instead be to just check
> the return value, and go from there? Should be a simple enough patch,
> something like the attached.


> Tom, can you comment?


Testing against INT_MAX seems like a type pun, or something. Maybe use
MaxAllocSize instead?

if (xfrmlen >= MaxAllocSize)
return val;

Also, since as you note returning (size_t) -1 is not at all standard,
it would be helpful to readers to note that that's what Windows does
on failure and that's what you're testing for. In fact you could
make a good case that the test should be just

if (xfrmlen == (size_t) -1)
return val;

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008, 10:00 AM
Magnus Hagander
 
Posts: n/a
Default Re: Clear up strxfrm() in UTF-8 with locale on Windows

On Wed, May 02, 2007 at 05:25:39PM -0400, Tom Lane wrote:
> Magnus Hagander <magnus@hagander.net> writes:
> > Given this, perhaps the proper approach should instead be to just check
> > the return value, and go from there? Should be a simple enough patch,
> > something like the attached.

>
> > Tom, can you comment?

>
> Testing against INT_MAX seems like a type pun, or something. Maybe use
> MaxAllocSize instead?


The windows API documentation specifically says:
On an error, each function sets errno and returns INT_MAX.

So actually an equality test against INT_MAX would be correct. But making
that clear in the comment would probably not be a bad idea :-)

//Magnus


---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-18-2008, 10:01 AM
Magnus Hagander
 
Posts: n/a
Default Re: Clear up strxfrm() in UTF-8 with locale on Windows

Magnus Hagander wrote:
> On Wed, May 02, 2007 at 05:25:39PM -0400, Tom Lane wrote:
>> Magnus Hagander <magnus@hagander.net> writes:
>>> Given this, perhaps the proper approach should instead be to just check
>>> the return value, and go from there? Should be a simple enough patch,
>>> something like the attached.
>>> Tom, can you comment?

>> Testing against INT_MAX seems like a type pun, or something. Maybe use
>> MaxAllocSize instead?

>
> The windows API documentation specifically says:
> On an error, each function sets errno and returns INT_MAX.
>
> So actually an equality test against INT_MAX would be correct. But making
> that clear in the comment would probably not be a bad idea :-)


I have applied a fix for this, because it obviously needed fixing
regardless of if it fixes the original issue all the way. Still looking
for confirmation if it does, though.

//Magnus

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-18-2008, 10:01 AM
ITAGAKI Takahiro
 
Posts: n/a
Default Re: Clear up strxfrm() in UTF-8 with locale on Windows


Magnus Hagander <magnus@hagander.net> wrote:

> > So actually an equality test against INT_MAX would be correct. But making
> > that clear in the comment would probably not be a bad idea :-)

>
> I have applied a fix for this, because it obviously needed fixing
> regardless of if it fixes the original issue all the way. Still looking
> for confirmation if it does, though.


The fix works well. I tested it with UTF-8 encoding and Japanese_Japan.932
(SJIS) locale and I didn't see any errors. I think it it is enough to cover
the buggy UTF-8 treatment on Windows.

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center



---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-18-2008, 10:01 AM
Magnus Hagander
 
Posts: n/a
Default Re: Clear up strxfrm() in UTF-8 with locale on Windows

> > > So actually an equality test against INT_MAX would be correct. But making
> > > that clear in the comment would probably not be a bad idea :-)

> >
> > I have applied a fix for this, because it obviously needed fixing
> > regardless of if it fixes the original issue all the way. Still looking
> > for confirmation if it does, though.

>
> The fix works well. I tested it with UTF-8 encoding and Japanese_Japan.932
> (SJIS) locale and I didn't see any errors. I think it it is enough to cover
> the buggy UTF-8 treatment on Windows.
>


Thanks for testing.

Bruce, that means the original patch is not needed, so you can take it off the patch queue. Thanks.

/Magnus


---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:35 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com