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
@@ -230,7 +230,7 @@ extern "C"
|
||||
int HALGetJoystickDescriptor(uint8_t joystickNum, HALJoystickDescriptor *desc);
|
||||
int HALGetJoystickIsXbox(uint8_t joystickNum);
|
||||
int HALGetJoystickType(uint8_t joystickNum);
|
||||
const char* HALGetJoystickName(uint8_t joystickNum);
|
||||
char* HALGetJoystickName(uint8_t joystickNum);
|
||||
int HALGetJoystickAxisType(uint8_t joystickNum, uint8_t axis);
|
||||
int HALSetJoystickOutputs(uint8_t joystickNum, uint32_t outputs, uint16_t leftRumble, uint16_t rightRumble);
|
||||
int HALGetMatchTime(float *matchTime);
|
||||
|
||||
@@ -273,7 +273,9 @@ uint32_t getAnalogOversampleBits(void* analog_port_pointer, int32_t *status) {
|
||||
int16_t getAnalogValue(void* analog_port_pointer, int32_t *status) {
|
||||
AnalogPort* port = (AnalogPort*) analog_port_pointer;
|
||||
int16_t value;
|
||||
checkAnalogInputChannel(port->port.pin);
|
||||
if (!checkAnalogInputChannel(port->port.pin)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tAI::tReadSelect readSelect;
|
||||
readSelect.Channel = port->port.pin;
|
||||
@@ -304,7 +306,9 @@ int16_t getAnalogValue(void* analog_port_pointer, int32_t *status) {
|
||||
int32_t getAnalogAverageValue(void* analog_port_pointer, int32_t *status) {
|
||||
AnalogPort* port = (AnalogPort*) analog_port_pointer;
|
||||
int32_t value;
|
||||
checkAnalogInputChannel(port->port.pin);
|
||||
if (!checkAnalogInputChannel(port->port.pin)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tAI::tReadSelect readSelect;
|
||||
readSelect.Channel = port->port.pin;
|
||||
|
||||
@@ -126,11 +126,11 @@ void initializeDigital(int32_t *status) {
|
||||
// Ensure that PWM output values are set to OFF
|
||||
for (uint32_t pwm_index = 0; pwm_index < kPwmPins; pwm_index++) {
|
||||
// Initialize port structure
|
||||
DigitalPort* digital_port = new DigitalPort();
|
||||
digital_port->port.pin = pwm_index;
|
||||
DigitalPort digital_port;
|
||||
digital_port.port.pin = pwm_index;
|
||||
|
||||
setPWM(digital_port, kPwmDisabled, status);
|
||||
setPWMPeriodScale(digital_port, 3, status); // Set all to 4x by default.
|
||||
setPWM(&digital_port, kPwmDisabled, status);
|
||||
setPWMPeriodScale(&digital_port, 3, status); // Set all to 4x by default.
|
||||
}
|
||||
|
||||
digitalSystemsInitialized = true;
|
||||
|
||||
@@ -209,7 +209,7 @@ CTR_Code PCM::FireOneShotSolenoid(UINT8 idx)
|
||||
CTR_Code PCM::SetOneShotDurationMs(UINT8 idx,uint32_t durMs)
|
||||
{
|
||||
/* sanity check caller's param */
|
||||
if(idx > 8)
|
||||
if(idx > 7)
|
||||
return CTR_InvalidParamValue;
|
||||
/* get latest tx frame */
|
||||
CtreCanNode::txTask<PcmControlSetOneShotDur_t> toFill = GetTx<PcmControlSetOneShotDur_t>(CONTROL_3 | GetDeviceNumber());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//This file must compile on ALL PLATFORMS. Be very careful what you put in here.
|
||||
#include "HAL/HAL.hpp"
|
||||
#include "FRC_NetworkCommunication/FRCComm.h"
|
||||
#include <cstring>
|
||||
|
||||
int HALGetControlWord(HALControlWord *data)
|
||||
{
|
||||
@@ -62,17 +63,20 @@ int HALGetJoystickType(uint8_t joystickNum)
|
||||
}
|
||||
}
|
||||
|
||||
const char* HALGetJoystickName(uint8_t joystickNum)
|
||||
char* HALGetJoystickName(uint8_t joystickNum)
|
||||
{
|
||||
HALJoystickDescriptor joystickDesc;
|
||||
if(HALGetJoystickDescriptor(joystickNum, &joystickDesc)<0)
|
||||
{
|
||||
const char* retval = "";
|
||||
return retval;
|
||||
char* name = (char*)std::malloc(1);
|
||||
name[0] = '\0';
|
||||
return name;
|
||||
} else
|
||||
{
|
||||
const char* retval(joystickDesc.name);
|
||||
return retval;
|
||||
size_t len = std::strlen(joystickDesc.name);
|
||||
char* name = (char*)std::malloc(len+1);
|
||||
std::strcpy(name, joystickDesc.name);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user