summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/wtf/StringExtras.h
diff options
context:
space:
mode:
Diffstat (limited to 'JavaScriptCore/wtf/StringExtras.h')
-rw-r--r--JavaScriptCore/wtf/StringExtras.h28
1 files changed, 21 insertions, 7 deletions
diff --git a/JavaScriptCore/wtf/StringExtras.h b/JavaScriptCore/wtf/StringExtras.h
index b1ec09f..473bb22 100644
--- a/JavaScriptCore/wtf/StringExtras.h
+++ b/JavaScriptCore/wtf/StringExtras.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,6 +28,7 @@
#include <stdarg.h>
#include <stdio.h>
+#include <string.h>
#if HAVE(STRINGS_H)
#include <strings.h>
@@ -43,17 +44,30 @@ inline int snprintf(char* buffer, size_t count, const char* format, ...)
va_start(args, format);
result = _vsnprintf(buffer, count, format, args);
va_end(args);
+
+ // In the case where the string entirely filled the buffer, _vsnprintf will not
+ // null-terminate it, but snprintf must.
+ if (count > 0)
+ buffer[count - 1] = '\0';
+
return result;
}
-#if COMPILER(MSVC7) || OS(WINCE)
-
-inline int vsnprintf(char* buffer, size_t count, const char* format, va_list args)
+inline double wtf_vsnprintf(char* buffer, size_t count, const char* format, va_list args)
{
- return _vsnprintf(buffer, count, format, args);
+ int result = _vsnprintf(buffer, count, format, args);
+
+ // In the case where the string entirely filled the buffer, _vsnprintf will not
+ // null-terminate it, but vsnprintf must.
+ if (count > 0)
+ buffer[count - 1] = '\0';
+
+ return result;
}
-#endif
+// Work around a difference in Microsoft's implementation of vsnprintf, where
+// vsnprintf does not null terminate the buffer. WebKit can rely on the null termination.
+#define vsnprintf(buffer, count, format, args) wtf_vsnprintf(buffer, count, format, args)
#if OS(WINCE)
@@ -86,7 +100,7 @@ inline int strcasecmp(const char* s1, const char* s2)
#endif
-#if OS(WINDOWS) || OS(LINUX) || OS(SOLARIS)
+#if COMPILER(MSVC) || COMPILER(RVCT) || OS(WINDOWS) || OS(LINUX) || OS(SOLARIS)
// FIXME: should check HAVE_STRNSTR
inline char* strnstr(const char* buffer, const char* target, size_t bufferLength)