Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/core/SkError.cpp

Issue 230413005: remove sprintf (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: AnotherPatchSet Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkTLS.h" 9 #include "SkTLS.h"
10 #include "SkTypes.h" 10 #include "SkTypes.h"
11 #include "SkError.h" 11 #include "SkError.h"
12 #include "SkErrorInternals.h" 12 #include "SkErrorInternals.h"
13 13
14 #include <stdio.h> 14 #include <stdio.h>
15 #include <stdarg.h> 15 #include <stdarg.h>
16 16
17 #ifdef SK_BUILD_FOR_WIN
18 #define SNPRINTF _snprintf
19 #else
20 #define SNPRINTF snprintf
21 #endif
22
17 namespace { 23 namespace {
18 void *CreateThreadError() { 24 void *CreateThreadError() {
19 return SkNEW_ARGS(SkError, (kNoError_SkError)); 25 return SkNEW_ARGS(SkError, (kNoError_SkError));
20 } 26 }
21 void DeleteThreadError(void* v) { 27 void DeleteThreadError(void* v) {
22 SkDELETE(reinterpret_cast<SkError*>(v)); 28 SkDELETE(reinterpret_cast<SkError*>(v));
23 } 29 }
24 #define THREAD_ERROR \ 30 #define THREAD_ERROR \
25 (*reinterpret_cast<SkError*>(SkTLS::Get(CreateThreadError, DeleteThreadE rror))) 31 (*reinterpret_cast<SkError*>(SkTLS::Get(CreateThreadError, DeleteThreadE rror)))
26 32
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 error_name = "Out Of Memory"; 128 error_name = "Out Of Memory";
123 break; 129 break;
124 case kParseError_SkError: 130 case kParseError_SkError:
125 error_name = "Parse Error"; 131 error_name = "Parse Error";
126 break; 132 break;
127 default: 133 default:
128 error_name = "Unknown error"; 134 error_name = "Unknown error";
129 break; 135 break;
130 } 136 }
131 137
132 sprintf( str, "%s: ", error_name ); 138 SNPRINTF(str, ERROR_STRING_LENGTH, "%s: ", error_name);
133 int string_left = SkToInt(ERROR_STRING_LENGTH - strlen(str)); 139 int string_left = SkToInt(ERROR_STRING_LENGTH - strlen(str));
134 str += strlen(str); 140 str += strlen(str);
135 141
136 va_start( args, fmt ); 142 va_start( args, fmt );
137 vsnprintf( str, string_left, fmt, args ); 143 vsnprintf( str, string_left, fmt, args );
138 va_end( args ); 144 va_end( args );
139 SkErrorCallbackFunction fn = THREAD_ERROR_CALLBACK; 145 SkErrorCallbackFunction fn = THREAD_ERROR_CALLBACK;
140 if (fn && code != kNoError_SkError) { 146 if (fn && code != kNoError_SkError) {
141 fn(code, THREAD_ERROR_CONTEXT); 147 fn(code, THREAD_ERROR_CONTEXT);
142 } 148 }
143 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698