Closed Bug 1295085 Opened 8 years ago Closed 8 years ago

Replace PR_snprintf and s[n]printf calls with SprintfLiteral in netwerk/

Categories

(Core :: Networking, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla51
Tracking Status
firefox51 --- fixed

People

(Reporter: cpeterson, Assigned: cpeterson)

References

Details

(Whiteboard: [necko-would-take])

Attachments

(1 file)

Replace some PR_snprintf and s[n]printf calls with MFBT's SprintfLiteral, a safer sprintf for printing to fixed-size character arrays. SprintfLiteral also requires some int64_t format specifiers to be replaced with standard macros like PRId64 and PRIX64.
Attachment #8781030 - Flags: review?(jduell.mcbugs)
May I ask what is the motivation here?  Why is s[n]printf bad?  Why do we again have an overload of ourselves and not use native CRT function?
Flags: needinfo?(cpeterson)
Whiteboard: [necko-would-take]
(In reply to Honza Bambas (:mayhemer) from comment #1)
> May I ask what is the motivation here?  Why is s[n]printf bad?  Why do we
> again have an overload of ourselves and not use native CRT function?

SprintfLiteral will automatically calculate the correct buffer size for character arrays, though the snprintf calls replaced in this patch using sizeof(buffer) were already correct. So changing them from the standard snprintf to a MFBT function might not be worthwhile. I can withdraw those changes, if you prefer to stick with snprintf() and sizeof(buffer).

More importantly, though, this patch also replaces NSPR's PR_snprintf (bug 1197205). Reducing NSPR usage is a worthy goal. :)
Flags: needinfo?(cpeterson)
Comment on attachment 8781030 [details] [diff] [review]
netwerk-SprintfLiteral.patch

Review of attachment 8781030 [details] [diff] [review]:
-----------------------------------------------------------------

> Reducing NSPR usage is a worthy goal.

+1
Attachment #8781030 - Flags: review?(jduell.mcbugs) → review+
Pushed by cpeterson@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/cf311c1a56f1
Replace PR_snprintf and s[n]printf calls with SprintfLiteral in netwerk/. r=jduell
https://hg.mozilla.org/mozilla-central/rev/cf311c1a56f1
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla51
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: