Skip to content

Commit

Permalink
Fix #435, Changes for string ops warnings
Browse files Browse the repository at this point in the history
Resize buffers and tweak string copies to avoid truncation warnings
in GCC 9.  Note the code was generally OK (handled truncation) but
the new compiler still generates warnings even with correct usage
of certain functions.

In the UT_os_printf macro, be sure to "use" the return value
of the snprintf() call, which avoids warnings about truncation.
  • Loading branch information
jphickey committed Apr 29, 2020
1 parent a2024ad commit adca7b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/os/shared/inc/os-shared-filesys.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ typedef struct
typedef struct
{
char device_name[OS_MAX_API_NAME]; /**< The name of the underlying block device, if applicable */
char volume_name[OS_MAX_API_NAME];
char system_mountpt[OS_MAX_PATH_LEN]; /**< The name/prefix where the contents are accessible in the host operating system */
char volume_name[OS_FS_VOL_NAME_LEN];
char system_mountpt[OS_MAX_LOCAL_PATH_LEN]; /**< The name/prefix where the contents are accessible in the host operating system */
char virtual_mountpt[OS_MAX_PATH_LEN]; /**< The name/prefix in the OSAL Virtual File system exposed to applications */
char *address;
uint32 blocksize;
Expand Down
11 changes: 7 additions & 4 deletions src/os/shared/src/osapi-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,21 @@ int32 OS_FileSys_InitLocalFromVolTable(OS_filesys_internal_record_t *local, cons
strcmp(Vol->DeviceName,"unused") != 0)
{
strncpy(local->volume_name, Vol->VolumeName, sizeof(local->volume_name)-1);
local->volume_name[sizeof(local->volume_name)-1] = 0;
}

if (isgraph((int)Vol->PhysDevName[0]) &&
strcmp(Vol->PhysDevName,"unused") != 0)
{
strncpy(local->system_mountpt, Vol->PhysDevName, sizeof(local->system_mountpt)-1);
local->system_mountpt[sizeof(local->system_mountpt)-1] = 0;
}

if (isgraph((int)Vol->MountPoint[0]) &&
strcmp(Vol->MountPoint,"unused") != 0)
{
strncpy(local->virtual_mountpt, Vol->MountPoint, sizeof(local->virtual_mountpt)-1);
local->virtual_mountpt[sizeof(local->virtual_mountpt)-1] = 0;
}

/*
Expand Down Expand Up @@ -471,10 +474,10 @@ int32 OS_FileSysAddFixedMap(uint32 *filesys_id, const char *phys_path, const cha

memset(local, 0, sizeof(*local));
global->name_entry = local->device_name;
strcpy(local->device_name, dev_name);
strcpy(local->volume_name, dev_name);
strcpy(local->system_mountpt, phys_path);
strcpy(local->virtual_mountpt, virt_path);
strncpy(local->device_name, dev_name, sizeof(local->device_name)-1);
strncpy(local->volume_name, dev_name, sizeof(local->volume_name)-1);
strncpy(local->system_mountpt, phys_path, sizeof(local->system_mountpt)-1);
strncpy(local->virtual_mountpt, virt_path, sizeof(local->virtual_mountpt)-1);

/*
* mark the entry that it is a fixed disk
Expand Down
2 changes: 1 addition & 1 deletion src/unit-tests/inc/ut_os_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static inline bool UtOsalImplemented(int32 Fn, const char *File, uint32 Line)
/*--------------------------------------------------------------------------------*/

#define UT_os_sprintf(buf,...) \
snprintf(buf,sizeof(buf),__VA_ARGS__)
do { int x = snprintf(buf,sizeof(buf),__VA_ARGS__); if (x > 0) buf[x] = 0; } while (0)

/*--------------------------------------------------------------------------------*/

Expand Down

0 comments on commit adca7b5

Please sign in to comment.