Closed Bug 553268 Opened 14 years ago Closed 14 years ago

windows _snprintf() may not work like VMPI_snprintf expects it to

Categories

(Tamarin Graveyard :: Virtual Machine, defect, P2)

x86
Windows XP
defect

Tracking

(Not tracked)

VERIFIED FIXED
flash10.1

People

(Reporter: edwsmith, Assigned: lhansen)

Details

(Whiteboard: Has patch)

Attachments

(1 file, 3 obsolete files)

From Nicholas Nethercote nanojit developer:

I just learnt the hard way that snprintf() doesn't exist on Windows.
There is _snprintf(), but it's unsafe -- it doesn't guarantee
terminating with a NUL char.  sprintf_s() is the function that does
that.

http://msdn.microsoft.com/en-us/library/2ts7cx93%28VS.80%29.aspx
http://msdn.microsoft.com/en-us/library/ce3zzk1k%28VS.80%29.aspx

I mention it because I see the following lines in TR:

./platform/win32/win32-platform.h:#define VMPI_snprintf		::_snprintf
./VMPI/SpyUtilsWin.cpp:	#pragma warning(disable: 4995) //disabling
warning for deprecated _snprintf
./VMPI/SpyUtilsWinMo.cpp:	#pragma warning(disable: 4995) //disabling
warning for deprecated _snprintf
Assignee: nobody → lhansen
Priority: -- → P2
Target Milestone: --- → flash10.1
Right.  The problem is that _snprintf_s does more than just NUL-terminate, it actually invokes an exception handler if the buffer can't accomodate the output.  We probably don't want that.
Attached patch PatchSplinter Review
Implements VMPI_snprintf and VMPI_vsnprintf as functions on Windows, with reasonable semantics.

Removes the warning-disabling pragmas for _snprintf usage.

Adds VMPI_vsnprintf to all the platform header files (only Windows had it).

Changes some uses in the eval code of non-VMPI functions to use VMPI functions - fallout from removing a use of _snprintf.
Attachment #433597 - Flags: review?(edwsmith)
Status: NEW → ASSIGNED
Whiteboard: Has patch
Attachment #433597 - Flags: review?(edwsmith) → review+
A selftest test case would be handy here.
Flags: in-testsuite?
tamarin-redux-argo changeset:   3846:1bc40e7217a8
tamarin-redux changeset:   4109:0e6e60921250
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Looks like this patch does not compile properly on windows mobile:

MMgc/GCLog.cpp(49) : error C3861: 'vsnprintf': identifier not found
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
(In reply to comment #5)
> Looks like this patch does not compile properly on windows mobile:
> 
> MMgc/GCLog.cpp(49) : error C3861: 'vsnprintf': identifier not found

Bummer for Windows Mobile.
Depends on: 554473
Attached patch Selftests for VMPI_snprintf (obsolete) — Splinter Review
These test basic functionality of VMPI_snprintf:

- formatting various types
- handling buffer overflow and termination
- return values

To the best of my knowledge I'm going after only ISO C functionality here.
Attachment #434375 - Flags: review?(edwsmith)
Attachment #434377 - Flags: review?(edwsmith)
Performs a rough-and-ready parse of the format string and hands individual problems off to _snprintf, and assembles a string from the results.  Unlike _snprintf and _vsnprintf it returns the number of chars that would have been printed had the buffer been large enough.

Does not quite obsolete patch #433597, but replaces part of it.
Attachment #434380 - Flags: review?(edwsmith)
Attachment #434377 - Flags: review?(edwsmith) → review+
Depends on: 554659
Comment on attachment 434377 [details] [diff] [review]
Turn two calls to vsnprintf into calls to VMPI_vsnprintf

Moved to bug #554659.
Attachment #434377 - Attachment is obsolete: true
Comment on attachment 434375 [details] [diff] [review]
Selftests for VMPI_snprintf

Cancelling review as patch will be moved.
Attachment #434375 - Flags: review?(edwsmith)
Comment on attachment 434380 [details] [diff] [review]
Reasonably conformant implementation of VMPI_vsnprintf

Cancelling review as patch will be moved.
Attachment #434380 - Flags: review?(edwsmith)
No longer depends on: 554473
Comment on attachment 434375 [details] [diff] [review]
Selftests for VMPI_snprintf

Moved to bug #554664
Attachment #434375 - Attachment is obsolete: true
Comment on attachment 434380 [details] [diff] [review]
Reasonably conformant implementation of VMPI_vsnprintf

Moved to bug #554664
Attachment #434380 - Attachment is obsolete: true
(In reply to comment #5)
> Looks like this patch does not compile properly on windows mobile:
> 
> MMgc/GCLog.cpp(49) : error C3861: 'vsnprintf': identifier not found

That issue is now tracked in bug #554659 as it turned out to be more complicated.
Status: REOPENED → RESOLVED
Closed: 14 years ago14 years ago
No longer depends on: 554659
Resolution: --- → FIXED
Test cases have been moved to bug #554664.
Flags: in-testsuite?
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: