summaryrefslogtreecommitdiff
path: root/libutils/RefBase.cpp
diff options
context:
space:
mode:
authorGeorge Burgess IV <gbiv@google.com>2016-03-02 14:02:55 -0800
committerGeorge Burgess IV <gbiv@google.com>2016-03-07 18:40:40 -0800
commite7aa2b2c8378b458345477d1f6d9904490263bb6 (patch)
tree125b6116858579422945357b40930b5738a94eab /libutils/RefBase.cpp
parentd1ec9c450d8dc9d24b5f0254111449ecfcbeaea6 (diff)
Cleanup uses of sprintf so we can deprecate it.
Also cleans up two instances of open() with useless mode params, and changes a few uses of snprintf to use sizeof(buffer) instead of hardcoded buffer sizes. Change-Id: If11591003d910c995e72ad8f75afd072c255a3c5
Diffstat (limited to 'libutils/RefBase.cpp')
-rw-r--r--libutils/RefBase.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp
index 02907ad67..ea1e4db84 100644
--- a/libutils/RefBase.cpp
+++ b/libutils/RefBase.cpp
@@ -190,17 +190,22 @@ public:
{
Mutex::Autolock _l(mMutex);
char buf[128];
- sprintf(buf, "Strong references on RefBase %p (weakref_type %p):\n", mBase, this);
+ snprintf(buf, sizeof(buf),
+ "Strong references on RefBase %p (weakref_type %p):\n",
+ mBase, this);
text.append(buf);
printRefsLocked(&text, mStrongRefs);
- sprintf(buf, "Weak references on RefBase %p (weakref_type %p):\n", mBase, this);
+ snprintf(buf, sizeof(buf),
+ "Weak references on RefBase %p (weakref_type %p):\n",
+ mBase, this);
text.append(buf);
printRefsLocked(&text, mWeakRefs);
}
{
char name[100];
- snprintf(name, 100, DEBUG_REFS_CALLSTACK_PATH "/%p.stack", this);
+ snprintf(name, sizeof(name), DEBUG_REFS_CALLSTACK_PATH "/%p.stack",
+ this);
int rc = open(name, O_RDWR | O_CREAT | O_APPEND, 644);
if (rc >= 0) {
write(rc, text.string(), text.length());
@@ -293,8 +298,8 @@ private:
char buf[128];
while (refs) {
char inc = refs->ref >= 0 ? '+' : '-';
- sprintf(buf, "\t%c ID %p (ref %d):\n",
- inc, refs->id, refs->ref);
+ snprintf(buf, sizeof(buf), "\t%c ID %p (ref %d):\n",
+ inc, refs->id, refs->ref);
out->append(buf);
#if DEBUG_REFS_CALLSTACK_ENABLED
out->append(refs->stack.toString("\t\t"));