Skip to content

Klocwork issues #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.swp
*.bin
.*
cscope.*
3 changes: 2 additions & 1 deletion cores/arduino/CDCSerialClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ int CDCSerialClass::read( void )

void CDCSerialClass::flush( void )
{
while (_tx_buffer->tail != _tx_buffer->head) {
while (_tx_buffer->tail != _tx_buffer->head) { /* This infinite loop is intentional
and requested by design */
delayMicroseconds(1);
}
}
Expand Down
1 change: 1 addition & 0 deletions cores/arduino/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ int i2c_openadapter(void)
SET_PIN_PULLUP(25, 1);

i2c_cfg_data_t i2c_cfg;
memset(&i2c_cfg, 0, sizeof(i2c_cfg_data_t));

i2c_cfg.speed = I2C_SLOW;
i2c_cfg.addressing_mode = I2C_7_Bit;
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main( void )

setup();

for (;;)
for (;;) /* This infinite loop is intentional and requested by design */
{
loop();
if (serialEventRun) serialEventRun();
Expand Down
36 changes: 12 additions & 24 deletions cores/arduino/wiring.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#define FREQ_MHZ ((ARCV2_TIMER0_CLOCK_FREQ)/1000000)
static const uint64_t MS_TO_CLKS = (FREQ_MHZ * 1000);

static uint64_t getTimeStampClks(void)
static inline __attribute__((always_inline))
uint64_t getTimeStampClks(void)
{
__asm__ volatile (
/* Disable interrupts - we don't want to be disturbed */
"clri r2 \n\t"
/* Load in r1 value of timer0_overflows */
"ld r1, %0 \n\t"
/* Read COUNT0 register */
"lr r0, [0x21] \n\t"
/* Read CONTROL0 register */
"lr r3, [0x22] \n\t"
/* If CONTROL0.IP is set COUNT0 reached LIMIT0 => r1 value might not be
* accurate => read COUNT0 again */
"bbit0.nt r3, 3, end \n\t"
/* Read COUNT0 again*/
"lr r0, [0x21] \n\t"
/* Timer0 overflowed => timer0_overflows++ */
"add r1, r1, 1 \n\t"
/***/
"end: \n\t"
"seti r2 \n\t"
: /* Output parameters and their constraints */
: "m"(timer0_overflows) /* Input parameters and their constraints */
: "r0", "r1", "r2", "r3" /* Killed registers */
);
uint32_t time_stamp;
int key = interrupt_lock();
uint64_t ret = timer0_overflows;
time_stamp = aux_reg_read(ARC_V2_TMR0_COUNT);
if (aux_reg_read(ARC_V2_TMR0_CONTROL) & (0x01 << 3)) {
time_stamp = aux_reg_read(ARC_V2_TMR0_COUNT);
ret++;
}
interrupt_unlock(key);
return ((ret << 32) | time_stamp);
}

void delay(uint32_t msec)
Expand Down
5 changes: 4 additions & 1 deletion libraries/CurieBle/src/BleCharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ BleCharacteristic::_setValue(void)
if (!_initialised)
return BLE_STATUS_WRONG_STATE;

if ((_data_len > BLE_MAX_ATTR_DATA_LEN) || (_data_len > _char_data.max_len))
return BLE_STATUS_NOT_ALLOWED;

status = ble_client_gatts_set_attribute_value(_handles.value_handle,
_data_len, _data, 0);
if (BLE_STATUS_SUCCESS != status)
Expand Down Expand Up @@ -201,7 +204,7 @@ BleStatus
BleCharacteristic::setValue(const String &str)
{
str.getBytes((unsigned char *)&_data, (unsigned int)_char_data.max_len, 0U);
_data_len = str.len + 1;
_data_len = str.length() + 1;
return _setValue();
}

Expand Down
5 changes: 4 additions & 1 deletion libraries/CurieBle/src/BleDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ BleDescriptor::_setValue(void)
if (!_initialised)
return BLE_STATUS_WRONG_STATE;

if (_desc.length > BLE_MAX_ATTR_DATA_LEN)
return BLE_STATUS_NOT_ALLOWED;

return ble_client_gatts_set_attribute_value(_handle, _desc.length, _data, 0);
}

Expand All @@ -93,7 +96,7 @@ BleStatus
BleDescriptor::setValue(const String &str)
{
str.getBytes((unsigned char *)&_data, (unsigned int)BLE_MAX_ATTR_DATA_LEN, 0U);
_desc.length = str.len + 1;
_desc.length = str.length() + 1;
return _setValue();
}

Expand Down
1 change: 1 addition & 0 deletions libraries/CurieBle/src/BleDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ BlePeripheral::getLocalAddress(BleDeviceAddress &address) const
return BLE_STATUS_WRONG_STATE;

ble_addr_t bda;
memset(&bda, 0, sizeof(ble_addr_t));
status = ble_client_gap_get_bda(&bda);
if (BLE_STATUS_SUCCESS != status)
return status;
Expand Down
2 changes: 1 addition & 1 deletion system/libarc32_arduino101/bootcode/interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct _IsrTableEntry __attribute__((section(".data"))) _IsrTable[SS_NUM_IRQS];
static void _dummy_isr(void)
{
__asm__ ("flag 0x01"); /* Set the halt flag => halt the CPU */
for(;;);
for(;;); /* This infinite loop is intentional and requested by design */
}

void interrupt_connect(unsigned int irq, void (*isr)(void))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ void _cfw_loop(void * queue)
{
struct cfw_message * message;
T_QUEUE_MESSAGE m;
while (1) {
while (1) { /* This infinite loop is intentional and requested by design */
queue_get_message(queue, &m, OS_WAIT_FOREVER, NULL );
message = (struct cfw_message *) m;
if (message != NULL ) {
Expand Down
7 changes: 5 additions & 2 deletions system/libarc32_arduino101/framework/src/infra/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ uint16_t port_alloc(void * queue)
{
struct port * ret = NULL;
uint32_t flags = interrupt_lock();
if (registered_port_count < MAX_PORTS) {
if ((registered_port_count < MAX_PORTS) && (registered_port_count >= 0)) {
ports[registered_port_count].id = registered_port_count + 1; /* don't use 0 as port.*/
ports[registered_port_count].cpu_id = get_cpu_id(); /* is overwritten in case of ipc */
ports[registered_port_count].queue = queue;
Expand All @@ -150,7 +150,10 @@ uint16_t port_alloc(void * queue)
panic(E_OS_ERR_NO_MEMORY);
}
interrupt_unlock(flags);
return ret->id;
if (ret != NULL)
return ret->id;
else
return 0;
}
#else
uint16_t port_alloc(void *queue)
Expand Down
11 changes: 7 additions & 4 deletions system/libarc32_arduino101/framework/src/os/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ void * cfw_alloc(int size, OS_ERR_TYPE * err) {
void * ptr;
unsigned int flags = interrupt_lock();
ptr = malloc(size+sizeof(void*));
(*(int*) ptr) = size;
if (ptr != NULL) {
(*(int*) ptr) = size;
#ifdef TRACK_ALLOCS
alloc_count++;
alloc_count++;
#endif
interrupt_unlock(flags);
return ptr;
interrupt_unlock(flags);
return ptr;
} else
return 0;
}

void cfw_free(void * ptr, OS_ERR_TYPE * err) {
Expand Down