Project: skia Issues People Development process History Sign in
New issue
Advanced search Search tips
Issue 2716 Replace calls to sprintf with calls to snprintf
Starred by 3 users Project Member Reported by scro...@google.com, Jul 2 2014 Back to list
Status: Started
Owner:
Cc:
Area: AndroidFramework
Priority: Medium
Type: Defect



Sign in to add a comment
When building for Android, we get warnings like the following:

src/core/SkRegion.cpp:204:94: warning: call to 'sprintf' declared with attribute warning: sprintf is often misused; please use snprintf [enabled by default]

We actually use sprintf in a lot of places. Alternatively, we could silence the warning.
 
Project Member Comment 1 by mtkl...@google.com, Jul 2 2014
Using snprintf where possible seems like a good idea.

If it's available (Linux), asprintf is also pretty handy: it allocates a a new char* for you that's exactly the right size.

You can do the same sort of thing manually with snprintf:
  char dummy;
  const size_t charsWeWouldHaveWritten = snprintf(&dummy, 1, "%f", number);
  SkAutoMalloc buffer(charsWeWouldHaveWritten + 1);
  SkAssertResult(charsWeWouldHaveWritten == snprintf(buffer.get(), charsWeWouldHaveWritten + 1, "%f", number);
Project Member Comment 2 by hcm@google.com, Oct 14 2014
Labels: Area-AndroidFramework
Project Member Comment 3 by hcm@google.com, Dec 7 2015
Labels: Hotlist-Fixit
Project Member Comment 4 by scro...@google.com, Feb 18 2016
Labels: GoodFirstBug
Owner: ----
Status: New
Project Member Comment 5 by caryclark@google.com, Mar 17 2016
Owner: caryclark@google.com
Project Member Comment 6 by caryclark@google.com, Oct 6 2016
Status: Started
Project Member Comment 7 by bugdroid1@chromium.org, Oct 6 2016
The following revision refers to this bug:
  https://skia.googlesource.com/skia.git/+/8f1864386734cfa7650a5576ba453745a407ade2

commit 8f1864386734cfa7650a5576ba453745a407ade2
Author: caryclark <caryclark@google.com>
Date: Thu Oct 06 18:46:25 2016

remove sprintf

Most uses of sprintf are
in pathops testing.

Replace them with
SkString::appendf

and replace the remaining
with snprintf

R=scroggo@google.com
BUG=skia:2716
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2391133005

Review-Url: https://codereview.chromium.org/2391133005

[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/src/core/SkError.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/src/core/SkRegion.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsOpCircleThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsOpCubicThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsOpLoopThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsOpRectThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsQuadLineIntersectionThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsSimplifyDegenerateThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsSimplifyQuadThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsSimplifyQuadralateralsThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsSimplifyRectThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsSimplifyTrianglesThreadedTest.cpp

Sign in to add a comment