mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
Fixed current and potential bugs caught by Coverity
Change-Id: I9f9d09dc797ffea062eeb49c881be1d5acb63d7b
This commit is contained in:
committed by
Peter Johnson
parent
b0fec4089b
commit
055ee09825
@@ -117,8 +117,10 @@ HSLImage *AxisCamera::GetImage() {
|
||||
int AxisCamera::CopyJPEG(char **destImage, unsigned int &destImageSize,
|
||||
unsigned int &destImageBufferSize) {
|
||||
std::lock_guard<priority_mutex> lock(m_imageDataMutex);
|
||||
if (destImage == nullptr)
|
||||
if (destImage == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "destImage must not be nullptr");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (m_imageData.size() == 0) return 0; // if no source image
|
||||
|
||||
@@ -440,6 +442,7 @@ void AxisCamera::ReadImagesFromCamera() {
|
||||
wpi_setWPIErrorWithContext(IncompatibleMode,
|
||||
"No content-length token found in packet");
|
||||
close(m_cameraSocket);
|
||||
if (imgBuffer) delete[] imgBuffer;
|
||||
return;
|
||||
}
|
||||
contentLength = contentLength + 16; // skip past "content length"
|
||||
@@ -564,8 +567,10 @@ int AxisCamera::CreateCameraSocket(std::string const &requestString,
|
||||
}
|
||||
|
||||
if (getaddrinfo(m_cameraHost.c_str(), "80", nullptr, &address) == -1) {
|
||||
if (setError)
|
||||
if (setError) {
|
||||
wpi_setErrnoErrorWithContext("Failed to create the camera socket");
|
||||
close(camSocket);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -573,10 +578,13 @@ int AxisCamera::CreateCameraSocket(std::string const &requestString,
|
||||
if (connect(camSocket, address->ai_addr, address->ai_addrlen) == -1) {
|
||||
if (setError)
|
||||
wpi_setErrnoErrorWithContext("Failed to connect to the camera");
|
||||
freeaddrinfo(address);
|
||||
close(camSocket);
|
||||
return -1;
|
||||
}
|
||||
|
||||
freeaddrinfo(address);
|
||||
|
||||
int sent = send(camSocket, requestString.c_str(), requestString.size(), 0);
|
||||
if (sent == -1) {
|
||||
if (setError)
|
||||
|
||||
@@ -69,6 +69,7 @@ void dprintf(const char *tempString, ...) /* Variable argument list */
|
||||
for (index = 0; index < tempStringLen; index++) {
|
||||
if (tempString[index] == ' ') {
|
||||
printf("ERROR in dprintf: malformed calling sequence (%s)\n", tempString);
|
||||
va_end(args);
|
||||
return;
|
||||
}
|
||||
if (tempString[index] == '\\' || tempString[index] == '/')
|
||||
@@ -292,6 +293,7 @@ int processFile(char *inputFile, char *outputString, int lineNumber) {
|
||||
FILE *infile;
|
||||
const int stringSize = 80; // max size of one line in file
|
||||
char inputStr[stringSize];
|
||||
inputStr[0] = '\0';
|
||||
int lineCount = 0;
|
||||
|
||||
if (lineNumber < 0) return (-1);
|
||||
@@ -323,14 +325,10 @@ int processFile(char *inputFile, char *outputString, int lineNumber) {
|
||||
if (lineNumber == 0) return (lineCount);
|
||||
// check for input out of range
|
||||
if (lineNumber > lineCount) return (-1);
|
||||
// return the line selected
|
||||
if (lineCount) {
|
||||
stripString(inputStr);
|
||||
strcpy(outputString, inputStr);
|
||||
return (lineCount);
|
||||
} else {
|
||||
return (-1);
|
||||
}
|
||||
// return the line selected; lineCount guaranteed to be greater than zero
|
||||
stripString(inputStr);
|
||||
strcpy(outputString, inputStr);
|
||||
return (lineCount);
|
||||
}
|
||||
|
||||
/** Ignore empty string
|
||||
|
||||
@@ -70,6 +70,7 @@ int frcDispose(const char* functionName, ...) /* Variable argument list */
|
||||
}
|
||||
disposalPtr = va_arg(disposalPtrList, void*);
|
||||
}
|
||||
va_end(disposalPtrList);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user