Skip to content

Commit

Permalink
Fix coverity warnings (#1917)
Browse files Browse the repository at this point in the history
* Fix coverity warnings

* Fix Host release build error
  • Loading branch information
mikee47 authored and slaff committed Oct 28, 2019
1 parent 276ff51 commit 0e648c1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion Sming/Arch/Host/Components/esp_hal/include/esp_systemapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ struct ip_addr {
#include <assert.h>

#include "debug_progmem.h"
#define debugf debug_i

#define SYSTEM_ERROR(fmt, ...) hostmsg("ERROR: " fmt "\r\n", ##__VA_ARGS__)

Expand Down
8 changes: 6 additions & 2 deletions Sming/Arch/Host/Components/hostlib/hostlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ int msleep(unsigned ms)

void getHostAppDir(char* path, size_t bufSize)
{
if(path == NULL ||bufSize == 0) {
return;
}

size_t len;
char sep;
#ifdef __WIN32
len = GetModuleFileName(NULL, path, bufSize);
len = GetModuleFileName(NULL, path, bufSize - 1);
sep = '\\';
#else
len = readlink("/proc/self/exe", path, bufSize);
len = readlink("/proc/self/exe", path, bufSize - 1);
sep = '/';
#endif
path[len] = '\0';
Expand Down
8 changes: 7 additions & 1 deletion Sming/Arch/Host/Components/lwip/Linux/host_lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ static struct netif netif;

static void getMacAddress(const char* ifname, uint8_t hwaddr[6])
{
if(ifname == NULL) {
return;
}

struct ifreq ifr = {0};
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ - 1] = '\0';

int fd = socket(AF_INET, SOCK_DGRAM, 0);
int res = ioctl(fd, SIOCGIFHWADDR, &ifr);
Expand Down Expand Up @@ -131,7 +136,8 @@ bool host_lwip_init(const struct lwip_param* param)

if(param->ipaddr == NULL) {
// Choose a default IP address
IP4_ADDR(&netcfg.ipaddr, (uint32_t)ip4_addr1(&netcfg.gw), (uint32_t)ip4_addr2(&netcfg.gw), (uint32_t)ip4_addr3(&netcfg.gw), 10U);
IP4_ADDR(&netcfg.ipaddr, (uint32_t)ip4_addr1(&netcfg.gw), (uint32_t)ip4_addr2(&netcfg.gw),
(uint32_t)ip4_addr3(&netcfg.gw), 10U);
} else if(ip4addr_aton(param->ipaddr, &netcfg.ipaddr) != 1) {
hostmsg("Failed to parse provided IP address '%s'", param->ipaddr);
return false;
Expand Down
1 change: 1 addition & 0 deletions Sming/Arch/Host/Components/spi_flash/flashmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ bool host_flashmem_init(FlashmemConfig& config)
{
if(config.filename != nullptr) {
strncpy(flashFileName, config.filename, sizeof(flashFileName));
flashFileName[sizeof(flashFileName) - 1] = '\0';
} else {
getHostAppDir(flashFileName, sizeof(flashFileName));
strcpy(flashFileName, defaultFlashFileName);
Expand Down

0 comments on commit 0e648c1

Please sign in to comment.