all: Replace strlen() call on const string with sizeof()-1
This commit is contained in:
1 parent
8d52950ede
commit
f0712d5b23
3 files changed
+12
-12
No files matched your search
+1
-1
@@ -495,7 +495,7 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) {
|
|||||||
|
|
||||||
if ( image->layout ) {
|
if ( image->layout ) {
|
||||||
|
|
||||||
layout_name = calloc(1, strlen(name) + strlen(".layout") + 1);
|
layout_name = calloc(1, strlen(name) + sizeof(".layout")-1 + 1);
|
||||||
if ( ! layout_name ) {
|
if ( ! layout_name ) {
|
||||||
free(name);
|
free(name);
|
||||||
ALLOC_ERROR_RETURN(-1);
|
ALLOC_ERROR_RETURN(-1);
|
||||||
|
|||||||
+7
-7
@@ -127,9 +127,9 @@ int local_init(void) {
|
|||||||
|
|
||||||
while ( fgets(buf, sizeof(buf), file) ) {
|
while ( fgets(buf, sizeof(buf), file) ) {
|
||||||
|
|
||||||
if ( strncmp(buf, "Hardware", strlen("Hardware")) == 0 ) {
|
if ( strncmp(buf, "Hardware", sizeof("Hardware")-1) == 0 ) {
|
||||||
|
|
||||||
ptr = buf + strlen("Hardware");
|
ptr = buf + sizeof("Hardware")-1;
|
||||||
|
|
||||||
while ( ptr < buf + sizeof(buf) && *ptr > 0 && *ptr <= 32 )
|
while ( ptr < buf + sizeof(buf) && *ptr > 0 && *ptr <= 32 )
|
||||||
++ptr;
|
++ptr;
|
||||||
@@ -328,7 +328,7 @@ int local_dump_image(enum image_type image, const char * file) {
|
|||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if ( strncmp(buf, "internal", strlen("internal")) != 0 )
|
if ( strncmp(buf, "internal", sizeof("internal")-1) != 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( snprintf(buf, sizeof(buf), "/sys/class/mmc_host/%s/%s:0001/", dirent->d_name, dirent->d_name) <= 0 )
|
if ( snprintf(buf, sizeof(buf), "/sys/class/mmc_host/%s/%s:0001/", dirent->d_name, dirent->d_name) <= 0 )
|
||||||
@@ -340,7 +340,7 @@ int local_dump_image(enum image_type image, const char * file) {
|
|||||||
|
|
||||||
while ( ( dirent2 = readdir(dir2) ) ) {
|
while ( ( dirent2 = readdir(dir2) ) ) {
|
||||||
|
|
||||||
if ( strncmp(dirent2->d_name, "block:mmcblk", strlen("block:mmcblk")) != 0 )
|
if ( strncmp(dirent2->d_name, "block:mmcblk", sizeof("block:mmcblk")-1) != 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( snprintf(buf, sizeof(buf), "/sys/class/mmc_host/%s/%s:0001/%s/dev", dirent->d_name, dirent->d_name, dirent2->d_name) <= 0 )
|
if ( snprintf(buf, sizeof(buf), "/sys/class/mmc_host/%s/%s:0001/%s/dev", dirent->d_name, dirent->d_name, dirent2->d_name) <= 0 )
|
||||||
@@ -540,7 +540,7 @@ int local_set_usb_host_mode(int enable) {
|
|||||||
|
|
||||||
int local_get_rd_mode(void) {
|
int local_get_rd_mode(void) {
|
||||||
|
|
||||||
if ( strncmp(rd_mode, "master", strlen("master")) == 0 )
|
if ( strncmp(rd_mode, "master", sizeof("master")-1) == 0 )
|
||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
@@ -559,8 +559,8 @@ int local_get_rd_flags(char * flags, size_t size) {
|
|||||||
|
|
||||||
const char * ptr;
|
const char * ptr;
|
||||||
|
|
||||||
if ( strncmp(rd_mode, "master", strlen("master")) == 0 )
|
if ( strncmp(rd_mode, "master", sizeof("master")-1) == 0 )
|
||||||
ptr = rd_mode + strlen("master");
|
ptr = rd_mode + sizeof("master")-1;
|
||||||
else
|
else
|
||||||
ptr = rd_mode;
|
ptr = rd_mode;
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -464,7 +464,7 @@ int nolo_flash_image(struct usb_device_info * dev, struct image * image) {
|
|||||||
if ( nolo_get_string(dev, "cmt:status", buf, sizeof(buf)) < 0 )
|
if ( nolo_get_string(dev, "cmt:status", buf, sizeof(buf)) < 0 )
|
||||||
NOLO_ERROR_RETURN("cmt:status failed", -1);
|
NOLO_ERROR_RETURN("cmt:status failed", -1);
|
||||||
|
|
||||||
if ( strncmp(buf, "idle", strlen("idle")) == 0 )
|
if ( strncmp(buf, "idle", sizeof("idle")-1) == 0 )
|
||||||
state = 4;
|
state = 4;
|
||||||
else
|
else
|
||||||
printf("Erasing CMT...\n");
|
printf("Erasing CMT...\n");
|
||||||
@@ -476,7 +476,7 @@ int nolo_flash_image(struct usb_device_info * dev, struct image * image) {
|
|||||||
NOLO_ERROR_RETURN("cmt:status failed", -1);
|
NOLO_ERROR_RETURN("cmt:status failed", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( strncmp(buf, "finished", strlen("finished")) == 0 ) {
|
if ( strncmp(buf, "finished", sizeof("finished")-1) == 0 ) {
|
||||||
|
|
||||||
if ( state <= 0 ) {
|
if ( state <= 0 ) {
|
||||||
printf_progressbar(last_total, last_total);
|
printf_progressbar(last_total, last_total);
|
||||||
@@ -537,9 +537,9 @@ int nolo_boot_device(struct usb_device_info * dev, const char * cmdline) {
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
int mode = NOLO_BOOT_MODE_NORMAL;
|
int mode = NOLO_BOOT_MODE_NORMAL;
|
||||||
|
|
||||||
if ( cmdline && strncmp(cmdline, "update", strlen("update")) == 0 && cmdline[strlen("update")] <= 32 ) {
|
if ( cmdline && strncmp(cmdline, "update", sizeof("update")-1) == 0 && cmdline[sizeof("update")-1] <= 32 ) {
|
||||||
mode = NOLO_BOOT_MODE_UPDATE;
|
mode = NOLO_BOOT_MODE_UPDATE;
|
||||||
cmdline += strlen("update");
|
cmdline += sizeof("update")-1;
|
||||||
if ( *cmdline ) ++cmdline;
|
if ( *cmdline ) ++cmdline;
|
||||||
while ( *cmdline && *cmdline <= 32 )
|
while ( *cmdline && *cmdline <= 32 )
|
||||||
++cmdline;
|
++cmdline;
|
||||||
|
|||||||
Reference in new issue
Block a user