Bug 964133 - Fix clang static analysis errors; r?jesup
MozReview-Commit-ID: I2vntE53ZdJ
--- a/media/webrtc/trunk/third_party/gflags/src/gflags.cc
+++ b/media/webrtc/trunk/third_party/gflags/src/gflags.cc
@@ -111,16 +111,17 @@
#include <vector>
#include "mutex.h"
#include "util.h"
#ifndef PATH_SEPARATOR
#define PATH_SEPARATOR '/'
#endif
+#include <mfbt/Sprintf.h>
// Special flags, type 1: the 'recursive' flags. They set another flag's val.
DEFINE_string(flagfile, "",
"load flags from file");
DEFINE_string(fromenv, "",
"set flags from the environment"
" [use 'export FLAGS_flag1=value']");
DEFINE_string(tryfromenv, "",
@@ -175,17 +176,17 @@ typedef bool (*ValidateFnProto)();
// Whether we should die when reporting an error.
enum DieWhenReporting { DIE, DO_NOT_DIE };
// Report Error and exit if requested.
static void ReportError(DieWhenReporting should_die, const char* format, ...) {
char error_message[255];
va_list ap;
va_start(ap, format);
- vsnprintf(error_message, sizeof(error_message), format, ap);
+ VsprintfLiteral(error_message, format, ap);
va_end(ap);
fprintf(stderr, "%s", error_message);
fflush(stderr); // should be unnecessary, but cygwin's rxvt buffers stderr
if (should_die == DIE) gflags_exitfunc(1);
}
// --------------------------------------------------------------------
@@ -343,26 +344,26 @@ bool FlagValue::ParseFrom(const char* va
}
string FlagValue::ToString() const {
char intbuf[64]; // enough to hold even the biggest number
switch (type_) {
case FV_BOOL:
return VALUE_AS(bool) ? "true" : "false";
case FV_INT32:
- snprintf(intbuf, sizeof(intbuf), "%" PRId32, VALUE_AS(int32));
+ SprintfLiteral(intbuf, "%" PRId32, VALUE_AS(int32));
return intbuf;
case FV_INT64:
- snprintf(intbuf, sizeof(intbuf), "%" PRId64, VALUE_AS(int64));
+ SprintfLiteral(intbuf, "%" PRId64, VALUE_AS(int64));
return intbuf;
case FV_UINT64:
- snprintf(intbuf, sizeof(intbuf), "%" PRIu64, VALUE_AS(uint64));
+ SprintfLiteral(intbuf, "%" PRIu64, VALUE_AS(uint64));
return intbuf;
case FV_DOUBLE:
- snprintf(intbuf, sizeof(intbuf), "%.17g", VALUE_AS(double));
+ SprintfLiteral(intbuf, "%.17g", VALUE_AS(double));
return intbuf;
case FV_STRING:
return VALUE_AS(string);
default:
assert(false);
return ""; // unknown type
}
}
--- a/media/webrtc/trunk/third_party/gflags/src/mutex.h
+++ b/media/webrtc/trunk/third_party/gflags/src/mutex.h
@@ -166,17 +166,17 @@ class Mutex {
// Create a Mutex that is not held by anybody. This constructor is
// typically used for Mutexes allocated on the heap or the stack.
inline Mutex();
// This constructor should be used for global, static Mutex objects.
// It inhibits work being done by the destructor, which makes it
// safer for code that tries to acqiure this mutex in their global
// destructor.
- inline Mutex(LinkerInitialized);
+ explicit inline Mutex(LinkerInitialized);
// Destructor
inline ~Mutex();
inline void Lock(); // Block if needed until free then acquire exclusively
inline void Unlock(); // Release a lock acquired via Lock()
#ifdef GMUTEX_TRYLOCK
inline bool TryLock(); // If free, Lock() and return true, else return false
@@ -197,17 +197,17 @@ class Mutex {
// always true. volatile is the most reliable way to do that.
volatile bool is_safe_;
// This indicates which constructor was called.
bool destroy_;
inline void SetIsSafe() { is_safe_ = true; }
// Catch the error of writing Mutex when intending MutexLock.
- Mutex(Mutex* /*ignored*/) {}
+ explicit Mutex(Mutex* /*ignored*/) {}
// Disallow "evil" constructors
Mutex(const Mutex&);
void operator=(const Mutex&);
};
// Now the implementation of Mutex for various systems
#if defined(NO_THREADS)
--- a/media/webrtc/trunk/third_party/gflags/src/util.h
+++ b/media/webrtc/trunk/third_party/gflags/src/util.h
@@ -43,16 +43,18 @@
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif // for mkdir()
+#include <mfbt/Sprintf.h>
+
_START_GOOGLE_NAMESPACE_
// This is used for unittests for death-testing. It is defined in gflags.cc.
extern GFLAGS_DLL_DECL void (*gflags_exitfunc)(int);
// Work properly if either strtoll or strtoq is on this system
#ifdef HAVE_STRTOLL
# define strto64 strtoll
@@ -256,17 +258,17 @@ inline void InternalStringPrintf(std::st
va_list ap) {
char space[128]; // try a small buffer and hope it fits
// It's possible for methods that use a va_list to invalidate
// the data in it upon use. The fix is to make a copy
// of the structure before using it and use that copy instead.
va_list backup_ap;
va_copy(backup_ap, ap);
- int bytes_written = vsnprintf(space, sizeof(space), format, backup_ap);
+ int bytes_written = VsprintfLiteral(space, format, backup_ap);
va_end(backup_ap);
if ((bytes_written >= 0) && (static_cast<size_t>(bytes_written) < sizeof(space))) {
output->append(space, bytes_written);
return;
}
// Repeatedly increase buffer size until it fits.
--- a/media/webrtc/trunk/webrtc/base/sigslot.h
+++ b/media/webrtc/trunk/webrtc/base/sigslot.h
@@ -248,17 +248,17 @@ namespace sigslot {
#endif // _SIGSLOT_HAS_POSIX_THREADS
template<class mt_policy>
class lock_block
{
public:
mt_policy *m_mutex;
- lock_block(mt_policy *mtx)
+ explicit lock_block(mt_policy *mtx)
: m_mutex(mtx)
{
m_mutex->lock();
}
~lock_block()
{
m_mutex->unlock();