From c99e89dfca747ec6da5a3f9d95708f29d4da8ae0 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Tue, 12 Jul 2016 10:46:34 -0700 Subject: [PATCH] Fixed the remaining cpplint.py warnings (#160) Replaced std::sprintf in BaeUtilities.cpp with std::stringstream and marked GetVisionErrorText() in FrcError.cpp as NOLINT --- wpilibc/athena/src/Vision/BaeUtilities.cpp | 37 +++++++++++----------- wpilibc/athena/src/Vision/FrcError.cpp | 2 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/wpilibc/athena/src/Vision/BaeUtilities.cpp b/wpilibc/athena/src/Vision/BaeUtilities.cpp index 609bf3625f..2608037f4c 100644 --- a/wpilibc/athena/src/Vision/BaeUtilities.cpp +++ b/wpilibc/athena/src/Vision/BaeUtilities.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include @@ -52,7 +54,6 @@ void dprintf(const char* tempString, ...) { const char* functionName; /* Format passed in argument */ const char* fmt; /* Format passed in argument */ char text[512]; /* Text string */ - char outtext[512]; /* Text string */ FILE* outfile_fd; /* Output file pointer */ char filepath[128]; /* Text string */ int fatalFlag = 0; @@ -96,35 +97,34 @@ void dprintf(const char* tempString, ...) { va_end(args); /* Format output statement */ + std::stringstream ss; + ss << std::setfill('0') << std::setw(4); + ss << "[" << filename << ":" << functionName << "@" << line_number << "] "; switch (type) { case DEBUG_TYPE: - std::sprintf(outtext, "[%s:%s@%04d] DEBUG %s\n", filename, functionName, - line_number, text); + ss << "DEBUG"; break; case INFO_TYPE: - std::sprintf(outtext, "[%s:%s@%04d] INFO %s\n", filename, functionName, - line_number, text); + ss << "INFO"; break; case ERROR_TYPE: - std::sprintf(outtext, "[%s:%s@%04d] ERROR %s\n", filename, functionName, - line_number, text); + ss << "ERROR"; break; case CRITICAL_TYPE: - std::sprintf(outtext, "[%s:%s@%04d] CRITICAL %s\n", filename, - functionName, line_number, text); + ss << "CRITICAL"; break; case FATAL_TYPE: fatalFlag = 1; - std::sprintf(outtext, "[%s:%s@%04d] FATAL %s\n", filename, functionName, - line_number, text); + ss << "FATAL"; break; default: std::printf("ERROR in dprintf: malformed calling sequence\n"); return; break; } + ss << " " << text << "\n"; - std::sprintf(filepath, "%s.debug", filename); + std::snprintf(filepath, sizeof(filepath), "%s.debug", filename); /* Write output statement */ switch (dprintfFlag) { @@ -134,24 +134,25 @@ void dprintf(const char* tempString, ...) { case DEBUG_MOSTLY_OFF: if (fatalFlag) { if ((outfile_fd = std::fopen(filepath, "a+")) != nullptr) { - std::fwrite(outtext, sizeof(char), std::strlen(outtext), outfile_fd); + std::fwrite(ss.str().c_str(), sizeof(char), ss.str().length(), + outfile_fd); std::fclose(outfile_fd); } } break; case DEBUG_SCREEN_ONLY: - std::printf("%s", outtext); + std::printf("%s", ss.str().c_str()); break; case DEBUG_FILE_ONLY: if ((outfile_fd = std::fopen(filepath, "a+")) != nullptr) { - fwrite(outtext, sizeof(char), strlen(outtext), outfile_fd); + fwrite(ss.str().c_str(), sizeof(char), ss.str().length(), outfile_fd); std::fclose(outfile_fd); } break; case DEBUG_SCREEN_AND_FILE: // BOTH - std::printf("%s", outtext); + std::printf("%s", ss.str().c_str()); if ((outfile_fd = std::fopen(filepath, "a+")) != nullptr) { - fwrite(outtext, sizeof(char), strlen(outtext), outfile_fd); + fwrite(ss.str().c_str(), sizeof(char), ss.str().length(), outfile_fd); std::fclose(outfile_fd); } break; @@ -331,7 +332,7 @@ int processFile(char* inputFile, char* outputString, int lineNumber) { if (lineNumber > lineCount) return (-1); // return the line selected; lineCount guaranteed to be greater than zero stripString(inputStr); - std::strcpy(outputString, inputStr); + std::strncpy(outputString, inputStr, kStringSize); return (lineCount); } diff --git a/wpilibc/athena/src/Vision/FrcError.cpp b/wpilibc/athena/src/Vision/FrcError.cpp index 4e5b384f80..973af069fc 100644 --- a/wpilibc/athena/src/Vision/FrcError.cpp +++ b/wpilibc/athena/src/Vision/FrcError.cpp @@ -2398,4 +2398,4 @@ const char* GetVisionErrorText(int errorCode) { } return errorText; -} +} // NOLINT