Closed Bug 57592 Opened 26 years ago Closed 25 years ago

Missing initialization of variable in mozilla\modules\libutil\src\nsTimer.cpp

Categories

(SeaMonkey :: General, defect, P3)

x86
Windows 2000
defect

Tracking

(Not tracked)

RESOLVED FIXED
mozilla0.9

People

(Reporter: bratell, Assigned: nisheeth_mozilla)

Details

(Whiteboard: [fix in hand])

Attachments

(2 files)

I got the following warning, compiling Mozilla g:\moz\mozillaprofile\mozilla\modules\libutil\src\nsTimer.cpp(30) : warning C4700: local variable 'argList' used without having been initialized Looking at the documentation of va_lists I think there's a va_start and va_end missing, but I really don't know much about va_lists. Could be a faulty compiler warning too. I looked at http://support.qnx.com/support/docs/qnx_neutrino/lib_ref/v/vprintf.html Patch: char* __mysprintf(char* aFormatString, ... ) { va_list argList; + va_start(argList); int size = vprintf(aFormatString, argList); char* buf = new char[size]; vsprintf(buf, aFormatString, argList); + va_end(argList); return buf; }
confirm that warning appears building debug on sources pulled 2000-11-14 on Win2k SP1. I don't know about whether the recommended patch is correct though.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla0.9
http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_crt_va_arg.2c_.va _end.2c_.va_start.htm is the online MSDN page that describes the va_start and va_end macros.
Whiteboard: [fix in hand]
I know nothing of this code, but looking at the documentation Nisheeth provided, I believe this is correct. Please try and test this stuff on our main platforms before landing. r=heikki.
Why do we even need __mysprintf in mozilla? It's used in exactly one place, in a macro and it's used like this: # define MOZ_TIMER_LOG(msg) \ do { \ char* str = __mysprintf msg; \ QuantifyAddAnnotation(str); \ delete [] str; \ } while (0) Why not use PR_smprintf() in stead of defining our own? Something like this: # define MOZ_TIMER_LOG(msg) \ do { \ char* str = PR_smprintf msg; \ QuantifyAddAnnotation(str); \ PR_smprintf_free(str); \ } while (0) (this requires prprf.h) If we'd do that we would not need the __mysprintf() method in mozilla at all (and it's not even conditionally built, admittedly not alot of code, but still) and we wouldn't need to deal with writing va_list code at all here. IMO this approach is much cleaner, and it fixes an ABW in the current implementation of __mysprintf(), the code looks like this: int size = vprintf(aFormatString, argList); char* buf = new char[size]; vsprintf(buf, aFormatString, argList); vprintf() returns the length of the resulting string *without* the trailing '\0' (according to UNIX man pages) so we'd need to do new char[size + 1] to avoid writing past the allocated buffer. Comments?
Yes, looks like NSPR should provide everything we need (didn't check what is the correct function, though). And we'd even get rid of the ABW.
Done. I agree that PR_smprintf is a much cleaner solution. I've cvs removed nsTimer.cpp and checked the patch that I'm about to attach in. Its pretty much what Johnny outline along with some build file changes. Marking bug fixed.
Attached patch Final patch — — Splinter Review
Really marking bug fixed.
Status: ASSIGNED → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
Product: Browser → Seamonkey
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: