removed a bunch of sprintf calls (some of them dangerous)
diff --git a/aos/externals/WPILib/WPILib/CAN/JaguarCANDriver.h b/aos/externals/WPILib/WPILib/CAN/JaguarCANDriver.h
index 35c82a5..0f8afe4 100644
--- a/aos/externals/WPILib/WPILib/CAN/JaguarCANDriver.h
+++ b/aos/externals/WPILib/WPILib/CAN/JaguarCANDriver.h
@@ -14,8 +14,6 @@
#ifndef __JaguarCANDriver_h__
#define __JaguarCANDriver_h__
-#include <VxWorks.h>
-
#ifdef __cplusplus
extern "C"
{
diff --git a/aos/externals/WPILib/WPILib/CANJaguar.cpp b/aos/externals/WPILib/WPILib/CANJaguar.cpp
index cf03370..ec55460 100644
--- a/aos/externals/WPILib/WPILib/CANJaguar.cpp
+++ b/aos/externals/WPILib/WPILib/CANJaguar.cpp
@@ -1223,7 +1223,7 @@
void CANJaguar::GetDescription(char *desc)
{
- sprintf(desc, "CANJaguar ID %d", m_deviceNumber);
+ snprintf(desc, 64, "CANJaguar ID %d", m_deviceNumber);
}
/**
diff --git a/aos/externals/WPILib/WPILib/Dashboard.cpp b/aos/externals/WPILib/WPILib/Dashboard.cpp
index c513baf..2235b99 100644
--- a/aos/externals/WPILib/WPILib/Dashboard.cpp
+++ b/aos/externals/WPILib/WPILib/Dashboard.cpp
@@ -29,7 +29,7 @@
{
m_userStatusData = new char[kMaxDashboardDataSize];
m_localBuffer = new char[kMaxDashboardDataSize];
- m_localPrintBuffer = new char[kMaxDashboardDataSize * 2];
+ m_localPrintBuffer = new char[kLocalPrintBufferSize];
m_localPrintBuffer[0] = 0;
m_packPtr = m_localBuffer;
m_printSemaphore = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE);
@@ -275,7 +275,7 @@
va_start (args, writeFmt);
{
Synchronized sync(m_printSemaphore);
- vsprintf(m_localPrintBuffer + strlen(m_localPrintBuffer), writeFmt, args);
+ vsnprintf(m_localPrintBuffer + strlen(m_localPrintBuffer), kLocalPrintBufferSize - strlen(m_localPrintBuffer), writeFmt, args);
size = strlen(m_localPrintBuffer);
}
if (size > kMaxDashboardDataSize)
diff --git a/aos/externals/WPILib/WPILib/Dashboard.h b/aos/externals/WPILib/WPILib/Dashboard.h
index dfcf989..1856660 100644
--- a/aos/externals/WPILib/WPILib/Dashboard.h
+++ b/aos/externals/WPILib/WPILib/Dashboard.h
@@ -50,6 +50,7 @@
void Flush() {}
private:
static const INT32 kMaxDashboardDataSize = USER_STATUS_DATA_SIZE - sizeof(UINT32) * 3 - sizeof(UINT8); // 13 bytes needed for 3 size parameters and the sequence number
+ static const size_t kLocalPrintBufferSize = kMaxDashboardDataSize * 2;
// Usage Guidelines...
DISALLOW_COPY_AND_ASSIGN(Dashboard);
diff --git a/aos/externals/WPILib/WPILib/DigitalModule.cpp b/aos/externals/WPILib/WPILib/DigitalModule.cpp
index 3e7f728..f5e357c 100644
--- a/aos/externals/WPILib/WPILib/DigitalModule.cpp
+++ b/aos/externals/WPILib/WPILib/DigitalModule.cpp
@@ -63,7 +63,7 @@
if (m_fpgaDIO->readLoopTiming(&localStatus) != kExpectedLoopTiming)
{
char err[128];
- sprintf(err, "DIO LoopTiming: %d, expecting: %d\n", m_fpgaDIO->readLoopTiming(&localStatus), kExpectedLoopTiming);
+ snprintf(err, sizeof(err), "DIO LoopTiming: %d, expecting: %d\n", m_fpgaDIO->readLoopTiming(&localStatus), kExpectedLoopTiming);
wpi_setWPIErrorWithContext(LoopTimingError, err);
}
m_fpgaDIO->writePWMConfig_Period(PWM::kDefaultPwmPeriod, &localStatus);
diff --git a/aos/externals/WPILib/WPILib/Error.cpp b/aos/externals/WPILib/WPILib/Error.cpp
index 30f0cbc..6c0941a 100644
--- a/aos/externals/WPILib/WPILib/Error.cpp
+++ b/aos/externals/WPILib/WPILib/Error.cpp
@@ -84,9 +84,9 @@
snprintf(error, 256, "%s: status = %d (0x%08X) %s ...in %s() in %s at line %d\n",
m_code < 0 ? "ERROR" : "WARNING", (INT32)m_code, (UINT32)m_code, m_message.c_str(),
m_function.c_str(), m_filename.c_str(), m_lineNumber);
- sprintf(error_with_code,"<Code>%d %s", (INT32)m_code, error);
+ snprintf(error_with_code, sizeof(error_with_code), "<Code>%d %s", (INT32)m_code, error);
} else {
- snprintf(error, 256, "ERROR: %s ...in %s() in %s at line %d\n", m_message.c_str(),
+ snprintf(error, sizeof(error), "ERROR: %s ...in %s() in %s at line %d\n", m_message.c_str(),
m_function.c_str(), m_filename.c_str(), m_lineNumber);
strcpy(error_with_code, error);
}
diff --git a/aos/externals/WPILib/WPILib/ErrorBase.cpp b/aos/externals/WPILib/WPILib/ErrorBase.cpp
index 2722963..9ee1fb1 100644
--- a/aos/externals/WPILib/WPILib/ErrorBase.cpp
+++ b/aos/externals/WPILib/WPILib/ErrorBase.cpp
@@ -62,7 +62,7 @@
int errNo = errnoGet();
if (errNo == 0)
{
- sprintf(err, "OK: %s", contextMessage);
+ snprintf(err, sizeof(err), "OK: %s", contextMessage);
}
else
{
@@ -101,7 +101,7 @@
// If there was an error
if (success <= 0) {
char err[256];
- sprintf(err, "%s: %s", contextMessage, imaqGetErrorText(imaqGetLastError()));
+ snprintf(err, sizeof(err), "%s: %s", contextMessage, imaqGetErrorText(imaqGetLastError()));
// Set the current error information for this object.
m_error.Set(imaqGetLastError(), err, filename, function, lineNumber, this);
@@ -152,7 +152,7 @@
const char* filename, const char* function, UINT32 lineNumber) const
{
char err[256];
- sprintf(err, "%s: %s", errorMessage, contextMessage);
+ snprintf(err, sizeof(err), "%s: %s", errorMessage, contextMessage);
// Set the current error information for this object.
m_error.Set(-1, err, filename, function, lineNumber, this);
@@ -195,7 +195,7 @@
const char* filename, const char* function, UINT32 lineNumber)
{
char err[256];
- sprintf(err, "%s: %s", errorMessage, contextMessage);
+ snprintf(err, sizeof(err), "%s: %s", errorMessage, contextMessage);
Synchronized mutex(_globalErrorMutex);
if (_globalError.GetCode() != 0) {
diff --git a/aos/externals/WPILib/WPILib/MotorSafety.h b/aos/externals/WPILib/WPILib/MotorSafety.h
index 15481d8..2c0734a 100644
--- a/aos/externals/WPILib/WPILib/MotorSafety.h
+++ b/aos/externals/WPILib/WPILib/MotorSafety.h
@@ -16,6 +16,7 @@
virtual void StopMotor() = 0;
virtual void SetSafetyEnabled(bool enabled) = 0;
virtual bool IsSafetyEnabled() = 0;
+ // desc is 64 bytes long.
virtual void GetDescription(char *desc) = 0;
};
diff --git a/aos/externals/WPILib/WPILib/RobotDrive.cpp b/aos/externals/WPILib/WPILib/RobotDrive.cpp
index 14e28f5..1d538c5 100644
--- a/aos/externals/WPILib/WPILib/RobotDrive.cpp
+++ b/aos/externals/WPILib/WPILib/RobotDrive.cpp
@@ -725,7 +725,7 @@
void RobotDrive::GetDescription(char *desc)
{
- sprintf(desc, "RobotDrive");
+ snprintf(desc, 64, "RobotDrive");
}
void RobotDrive::StopMotor()
diff --git a/aos/externals/WPILib/WPILib/SafePWM.cpp b/aos/externals/WPILib/WPILib/SafePWM.cpp
index 484fbe6..989d782 100644
--- a/aos/externals/WPILib/WPILib/SafePWM.cpp
+++ b/aos/externals/WPILib/WPILib/SafePWM.cpp
@@ -100,7 +100,7 @@
void SafePWM::GetDescription(char *desc)
{
- sprintf(desc, "PWM %d on module %d", GetChannel(), GetModuleNumber());
+ snprintf(desc, 64, "PWM %d on module %d", GetChannel(), GetModuleNumber());
}
/**
diff --git a/aos/externals/WPILib/WPILib/Utility.cpp b/aos/externals/WPILib/WPILib/Utility.cpp
index 5ce84f9..2ca0f03 100644
--- a/aos/externals/WPILib/WPILib/Utility.cpp
+++ b/aos/externals/WPILib/WPILib/Utility.cpp
@@ -34,7 +34,7 @@
cplusDemangle(name, label, sizeof(label) - 11);
if ((UINT)pVal != addr)
{
- sprintf(&label[strlen(label)], "+0x%04x", addr-pVal);
+ snprintf(label + strlen(label), sizeof(label) - strlen(label), "+0x%04x", addr-pVal);
if (found) *found = 2;
}
else
@@ -44,7 +44,7 @@
}
else
{
- sprintf(label, "0x%04x", addr);
+ snprintf(label, sizeof(label), "0x%04x", addr);
if (found) *found = 0;
}
@@ -56,15 +56,15 @@
char buf [MAX_SYS_SYM_LEN * 2];
INT32 ix;
INT32 len = 0;
- len += sprintf (&buf [len], "%s <%#010x>: ", wpi_getLabel((UINT)caller), (INT32)caller);
- len += sprintf (&buf [len], "%s <%#010x> (", wpi_getLabel((UINT)func), func);
+ len += snprintf (&buf [len], sizeof(buf) - len, "%s <%#010x>: ", wpi_getLabel((UINT)caller), (INT32)caller);
+ len += snprintf (&buf [len], sizeof(buf) - len, "%s <%#010x> (", wpi_getLabel((UINT)func), func);
for (ix = 0; ix < nargs; ix++)
{
if (ix != 0)
- len += sprintf (&buf [len], ", ");
- len += sprintf (&buf [len], "%#x", args [ix]);
+ len += snprintf (&buf [len], sizeof(buf) - len, ", ");
+ len += snprintf (&buf [len], sizeof(buf) - len, "%#x", args [ix]);
}
- len += sprintf (&buf [len], ")\n");
+ len += snprintf (&buf [len], sizeof(buf) - len, ")\n");
printf(buf);
}
@@ -107,23 +107,23 @@
}
char *funcNameEnd = strchr(funcName, '(');
*funcNameEnd = 0;
- len += sprintf (&buf [len], funcName);
+ len += snprintf (buf + len, sizeof(buf) - len, funcName);
// If this is a member function, print out the this pointer value.
if (totalnargs - params == 1)
{
- len += sprintf (&buf [len], "<this=%#x>", args [0]);
+ len += snprintf (buf + len, sizeof(buf) - len, "<this=%#x>", args [0]);
}
// Print out the argument values.
- len += sprintf (&buf [len], "(");
+ len += snprintf (buf + len, sizeof(buf) - len, "(");
for (ix = totalnargs - params; ix < nargs; ix++)
{
if (ix != totalnargs - params)
- len += sprintf (&buf [len], ", ");
- len += sprintf (&buf [len], "%#x", args [ix]);
+ len += snprintf (buf + len, sizeof(buf) - len, ", ");
+ len += snprintf (buf + len, sizeof(buf) - len, "%#x", args [ix]);
}
- len += sprintf (&buf [len], ")\n");
+ len += snprintf (buf + len, sizeof(buf) - len, ")\n");
printf(buf);
}
@@ -212,10 +212,10 @@
// If an error message was specified, include it
// Build error string
if(message != NULL) {
- sprintf(error, "Assertion failed: \"%s\", \"%s\" failed in %s() in %s at line %d\n",
+ snprintf(error, sizeof(error), "Assertion failed: \"%s\", \"%s\" failed in %s() in %s at line %d\n",
message, conditionText, funcName, fileName, lineNumber);
} else {
- sprintf(error, "Assertion failed: \"%s\" in %s() in %s at line %d\n",
+ snprintf(error, sizeof(error), "Assertion failed: \"%s\" in %s() in %s at line %d\n",
conditionText, funcName, fileName, lineNumber);
}
@@ -248,10 +248,10 @@
// If an error message was specified, include it
// Build error string
if(message != NULL) {
- sprintf(error, "Assertion failed: \"%s\", \"%d\" %s \"%d\" in %s() in %s at line %d\n",
+ snprintf(error, sizeof(error), "Assertion failed: \"%s\", \"%d\" %s \"%d\" in %s() in %s at line %d\n",
message, valueA, equalityType, valueB, funcName, fileName, lineNumber);
} else {
- sprintf(error, "Assertion failed: \"%d\" %s \"%d\" in %s() in %s at line %d\n",
+ snprintf(error, sizeof(error), "Assertion failed: \"%d\" %s \"%d\" in %s() in %s at line %d\n",
valueA, equalityType, valueB, funcName, fileName, lineNumber);
}