Closed Bug 614931 Opened 14 years ago Closed 14 years ago

Number.toLocaleString adds trailing NULL-byte

Categories

(Core :: JavaScript Engine, defect, P3)

x86
macOS
defect

Tracking

()

RESOLVED FIXED
mozilla2.0b9
Tracking Status
blocking2.0 --- betaN+

People

(Reporter: jandem, Assigned: bzbarsky)

References

Details

(Keywords: regression, Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file, 1 obsolete file)

---
js> (3.14).toLocaleString()
"3.14\0"
js> (3.14).toLocaleString().length
5
---
I only see this in the shell (OS X, x86/x64, GCC 4.2.1). Tinderbox browser build works OK. Can anybody reproduce?
Yes, I can reproduce.

I don't see how this could possibly not happen everywhere, though.  The code added in bug 446494 is just broken:


760     size = digits + (*nint ? strlen(nint + 1) + 1 : 0);
761     if (*nint == '.')
762         size += decimalLength;

It needs to take out the "+1" after the strlen call, as far as I can see, since it's accounting for the decimalLength separately...

Brian, am I just missing something?
Blocks: 446494
Keywords: regression
bz: Yeah, looks like you're right.  Removing that + 1 doesn't regress the other case, either.  r=me  :)
The reason this doesn't happen in the browser is that the browser impl of cx->localeCallbacks->localeToUnicode goes through intl code, which I bet treats that null byte as the actual end of string.
Assignee: general → bzbarsky
Priority: -- → P3
Whiteboard: [need review]
Comment on attachment 495762 [details] [diff] [review]
Number.toLocaleString shouldn't miscumpute the string length.

size is simply the wrong name -- it's the canonical name (along with nbytes) for a size_ allocation size, not net length in scaled elements. Suggest len, length, or buflen instead. r=me with that.

/be
Attachment #495762 - Flags: review?(brendan) → review+
OK, will rename to buflen.

Is this something I should try to get in for 2.0, given that it doesn't affect browser?
Note that this probably does affect some parts of the browser (XPCOM components, maybe JS modules?), given bug 441370.
That's a dup of bug 616841, which is a blocker.  So it really won't be much of a problem.  But ok, I'll try to get this landed.
Attachment #495762 - Attachment is obsolete: true
Given the comments in bug 616841, we're not likely to fix it in various contexts like workers...  So this should probably block.
blocking2.0: --- → ?
Whiteboard: [need review] → [need approval]
Attachment #499363 - Flags: approval2.0?
blocking2.0: ? → betaN+
Whiteboard: [need approval] → [need landing]
Attachment #499363 - Flags: approval2.0?
Pushed http://hg.mozilla.org/tracemonkey/rev/921fb4d04aca and then pushed http://hg.mozilla.org/tracemonkey/rev/e02379fdaf42 for the test.
Status: NEW → RESOLVED
Closed: 14 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla2.0b9
Whiteboard: [need landing]
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Whiteboard: fixed-in-tracemonkey
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: