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
« no previous file with comments | « platform_tools/android/launcher/skia_launcher.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #endif
20
17 namespace { 21 namespace {
18 void *CreateThreadError() { 22 void *CreateThreadError() {
19 return SkNEW_ARGS(SkError, (kNoError_SkError)); 23 return SkNEW_ARGS(SkError, (kNoError_SkError));
20 } 24 }
21 void DeleteThreadError(void* v) { 25 void DeleteThreadError(void* v) {
22 SkDELETE(reinterpret_cast<SkError*>(v)); 26 SkDELETE(reinterpret_cast<SkError*>(v));
23 } 27 }
24 #define THREAD_ERROR \ 28 #define THREAD_ERROR \
25 (*reinterpret_cast<SkError*>(SkTLS::Get(CreateThreadError, DeleteThreadE rror))) 29 (*reinterpret_cast<SkError*>(SkTLS::Get(CreateThreadError, DeleteThreadE rror)))
26 30
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 error_name = "Out Of Memory"; 126 error_name = "Out Of Memory";
123 break; 127 break;
124 case kParseError_SkError: 128 case kParseError_SkError:
125 error_name = "Parse Error"; 129 error_name = "Parse Error";
126 break; 130 break;
127 default: 131 default:
128 error_name = "Unknown error"; 132 error_name = "Unknown error";
129 break; 133 break;
130 } 134 }
131 135
132 sprintf( str, "%s: ", error_name ); 136 snprintf(str, ERROR_STRING_LENGTH, "%s: ", error_name);
133 int string_left = SkToInt(ERROR_STRING_LENGTH - strlen(str)); 137 int string_left = SkToInt(ERROR_STRING_LENGTH - strlen(str));
134 str += strlen(str); 138 str += strlen(str);
135 139
136 va_start( args, fmt ); 140 va_start( args, fmt );
137 vsnprintf( str, string_left, fmt, args ); 141 vsnprintf( str, string_left, fmt, args );
138 va_end( args ); 142 va_end( args );
139 SkErrorCallbackFunction fn = THREAD_ERROR_CALLBACK; 143 SkErrorCallbackFunction fn = THREAD_ERROR_CALLBACK;
140 if (fn && code != kNoError_SkError) { 144 if (fn && code != kNoError_SkError) {
141 fn(code, THREAD_ERROR_CONTEXT); 145 fn(code, THREAD_ERROR_CONTEXT);
142 } 146 }
143 } 147 }
OLDNEW
« no previous file with comments | « platform_tools/android/launcher/skia_launcher.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698