Closed Bug 58284 Opened 25 years ago Closed 24 years ago

wide string literals created by NS_ConvertASCIItoUCS2

Categories

(Core :: XPCOM, defect, P3)

x86
Linux
defect

Tracking

()

RESOLVED DUPLICATE of bug 104159
mozilla1.0

People

(Reporter: dbaron, Assigned: jag+mozilla)

References

()

Details

(Keywords: meta)

Attachments

(6 files)

There are lots of wide string literals that should use NS_LITERAL_STRING that are being created using NS_ConvertASCIItoUCS2 (which is how NS_LITERAL_STRING works on platforms that don't support 2-byte L"literal"). The following LXR search should show a nearly complete list: http://lxr.mozilla.org/seamonkey/search?string=NS_ConvertASCIItoUCS2%28%22 It also shows some examples of other bad string usage.
Some other bad (IMO) string usage I've seen in that query: - Using AppendWithConversion when only Append is needed - nsAutoString() [although this may sometimes be an out param that is ignored] - appending a single-character string instead of a PRUnichar - "nsString(NS_ConvertASCIItoUCS2("Server: %s - port %d")).GetUnicode()"
Blake accidentally checked in the changes to nsNNTPProtocol.cpp, which caused the following bustage on speedracer: nsNNTPProtocol.cpp: In method `int nsNNTPProtocol::DisplayNewsRC()': nsNNTPProtocol.cpp:3679: ambiguous conversion from `nsCString' to `bool' nsNNTPProtocol.cpp:3679: candidate conversions include `const char *' and `char *' nsNNTPProtocol.cpp:3679: `class nsCString' used where a `bool' was expected nsNNTPProtocol.cpp:3679: ambiguous default type conversion for `operator &&' nsNNTPProtocol.cpp:3730: warning: negative value `-1' passed as argument 2 of `nsNNTPProtocol::SetProgressBarPercent(unsigned int, unsigned int)' I'm not sure if that ever returns false without the change...
Okay, I've updated the patch and split it up. I just attached the |get()| addition to nsString.h and moving |GetBuffer()| from nsString.cpp to nsString.h, as soon as my build is done compiling (like, tomorrow) I will attach the actual conversions to NS_LITERAL_STRING themselves.
r=dbaron on the most recent patch, assuming scc super-reviews it, since he's module owner.
A few thoughts: * you're changing code generated by the DOM idlc. It would be trivial to fix the DOM idlc, but it looks like the code it calls takes an nsString& and just converts it to a C string. So why bother with either NS_LITERAL_STRING or NS_ConvertASCIItoUCS2? * What happens when the NS_ConvertASCIItoUCS2 was used as a parameter to a function taking an nsString& (or something similar). How does that compile? I thought those constructors were |explicit|. So what conversion is used?
It turns out I'm bitten by this compiling on linux with gcc 2.95.2 because the macro for NS_LITERAL_STRING here is just NS_ConvertASCIItoUCS2. On other platforms it's nsLiteralString which is derived from nsAReadableString and isn't interchangable with nsAutoString (which via via inherits from nsAReadableString) for some uses, so half of this wouldn't have compiled on those platforms. I'll go over these changes closely and will attach a new patch sometime.
I'm gotten a partial patch from jag for nsNNTPProtocol and I'm going to land it with other fixes.
sr=scc for the <a href="http://bugzilla.mozilla.org/showattachment.cgi?attach_id=20389">|.get()| patch</a> (12/08/00 19:59)
NS_ConvertToString is just |#define|d to be NS_ConvertASCIItoUCS2, so we should also deal with all the cases shown in: http://lxr.mozilla.org/seamonkey/search?string=NS_ConvertToString%28%22
Assignee: jag → jaggernaut
->moz1.0
Target Milestone: --- → mozilla1.0
*** This bug has been marked as a duplicate of 104159 ***
Status: NEW → RESOLVED
Closed: 24 years ago
Resolution: --- → DUPLICATE
Component: XP Miscellany → String
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: