Ignore:
Timestamp:
Jul 3, 2010, 5:11:41 PM (15 years ago)
Author:
[email protected]
Message:

Patch for https://bugs.webkit.org/show_bug.cgi?id=41553
Make StringExtras.h versions of snprintf and vsnprintf match the unix versions.

Reviewed by Darin Adler.

  • MSVC does not ensure the buffers are null terminated as the unix versions do.
  • runtime/JSGlobalObjectFunctions.cpp: Cleanup includes.
  • runtime/UString.cpp: Clean up includes.

(JSC::UString::from): Don't pass sizeof(buf) - 1, that is wrong.

  • wtf/StringExtras.h:

(snprintf): Ensure null termination of buffer.
(vsnprintf): Ditto.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/StringExtras.h

    r61489 r62457  
    11/*
    2  * Copyright (C) 2006 Apple Inc. All rights reserved.
     2 * Copyright (C) 2006, 2010 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4545    result = _vsnprintf(buffer, count, format, args);
    4646    va_end(args);
     47
     48    // In the case where the string entirely filled the buffer, _vsnprintf will not
     49    // null-terminate it, but snprintf must.
     50    if (count > 0)
     51        buffer[count - 1] = '\0';
     52
    4753    return result;
    4854}
    4955
    50 #if COMPILER(MSVC7_OR_LOWER) || OS(WINCE)
     56inline double wtf_vsnprintf(char* buffer, size_t count, const char* format, va_list args)
     57{
     58    int result = _vsnprintf(buffer, count, format, args);
    5159
    52 inline int vsnprintf(char* buffer, size_t count, const char* format, va_list args)
    53 {
    54     return _vsnprintf(buffer, count, format, args);
     60    // In the case where the string entirely filled the buffer, _vsnprintf will not
     61    // null-terminate it, but vsnprintf must.
     62    if (count > 0)
     63        buffer[count - 1] = '\0';
     64
     65    return result;
    5566}
    5667
    57 #endif
     68// Work around a bug in Microsoft's implementation of vsnprintf, where
     69// vsnprintf does not null terminate the buffer
     70#define vsnprintf(buffer, count, format, args) wtf_vsnprintf(buffer, count, format, args)
    5871
    5972#if OS(WINCE)
Note: See TracChangeset for help on using the changeset viewer.