Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1601 (new defect)

Opened 15 years ago

Last modified 14 years ago

tango.text.locale.Posix broken

Reported by: fawzi Assigned to: JarrettBillingsley
Priority: major Milestone: 1.0
Component: Tango Version: 0.99.8 Sean
Keywords: Cc:

Description

tango.text.locale.Posix compareString has a serious bug: strcoll expects its string to be zero terminated, but this is not ensured. Dues to this the unit tests can fail with a low probability (equal string are found different). In teal world usage with dynamic strings the failure is even more likely.

I have to say that I find even the interface of compareString questionable: why pass arrays + offset & length? the caller can easily build the slice before calling the function.

Furthermore why switching locale & co and not simply use strcoll_l?

Change History

04/17/09 17:49:21 changed by kris

  • owner changed from kris to JarrettBillingsley.

06/27/09 15:52:36 changed by JarrettBillingsley

I agree that the string+offset+length is odd. I think it was done that way because that matches the Windows API function for doing string compares, but.. that's still unnecessary :)

I'm also guessing that strcoll is used instead of strcoll_l because strcoll_l is only in the Posix 1.2008 standard; strcoll is more likely to be available on more platforms. Or it could be that the original author wasn't aware of it. Or it wasn't even available at the time of writing (four years ago!).

Also, I'm looking at this code and.. wtf. Really. Look at the code for compareString. It slices the source strings into s1 and s2, and then.. slices s1 and s2 again with the same offsets? WHAT

I'm surprised that this code even works. Or does it?

02/01/10 20:25:21 changed by larsivi

  • milestone changed from 0.99.9 to 1.0.