From bc1e9da659bf4b40615fe452cc5395098e724bde Mon Sep 17 00:00:00 2001 From: liquanqing Date: Tue, 30 Apr 2019 16:25:16 +0800 Subject: [PATCH 1/2] fix warning in cJson.c --- .../plugins/types/struct2json/src/cJSON.c | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/easyflash/plugins/types/struct2json/src/cJSON.c b/easyflash/plugins/types/struct2json/src/cJSON.c index f7bed44..6210fa7 100644 --- a/easyflash/plugins/types/struct2json/src/cJSON.c +++ b/easyflash/plugins/types/struct2json/src/cJSON.c @@ -52,7 +52,7 @@ static char* cJSON_strdup(const char* str) char* copy; len = strlen(str) + 1; - if (!(copy = (char*)cJSON_malloc(len))) return 0; + if ((copy = (char*)cJSON_malloc(len)) == NULL) return 0; memcpy(copy,str,len); return copy; } @@ -276,8 +276,27 @@ static char *print_string_ptr(const char *str,printbuffer *p) strcpy(out,"\"\""); return out; } - ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;} - + + ptr=str; +#if 0 + while ((token=*ptr) && ++len) + { + if (strchr("\"\\\b\f\n\r\t",token)) + len++; + else if (token<32) + len+=5; + ptr++; + } +#else + do { + token=*ptr; + if (strchr("\"\\\b\f\n\r\t",token)) + len++; + else if (token<32) + len+=5; + ptr++; + } while (token && ++len); +#endif if (p) out=ensure(p,len+3); else out=(char*)cJSON_malloc(len+3); if (!out) return 0; @@ -350,7 +369,7 @@ char *cJSON_PrintBuffered(cJSON *item,int prebuffer,int fmt) p.length=prebuffer; p.offset=0; return print_value(item,0,fmt,&p); - return p.buffer; + //return p.buffer; } @@ -421,7 +440,7 @@ static const char *parse_array(cJSON *item,const char *value) while (*value==',') { cJSON *new_item; - if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */ + if ((new_item=cJSON_New_Item()) == NULL) return 0; /* memory fail */ child->next=new_item;new_item->prev=child;child=new_item; value=skip(parse_value(child,skip(value+1))); if (!value) return 0; /* memory fail */ @@ -533,7 +552,7 @@ static const char *parse_object(cJSON *item,const char *value) while (*value==',') { cJSON *new_item; - if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */ + if ((new_item=cJSON_New_Item()) == NULL) return 0; /* memory fail */ child->next=new_item;new_item->prev=child;child=new_item; value=skip(parse_string(child,skip(value+1))); if (!value) return 0; From 249c59f6401155c1702e7fbae83822e7db8e61bc Mon Sep 17 00:00:00 2001 From: liquanqing Date: Tue, 30 Apr 2019 16:53:49 +0800 Subject: [PATCH 2/2] fix one bug after fix warning --- .../plugins/types/struct2json/src/cJSON.c | 23 ++----------------- easyflash/src/ef_log.c | 4 ++-- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/easyflash/plugins/types/struct2json/src/cJSON.c b/easyflash/plugins/types/struct2json/src/cJSON.c index 6210fa7..4e3e480 100644 --- a/easyflash/plugins/types/struct2json/src/cJSON.c +++ b/easyflash/plugins/types/struct2json/src/cJSON.c @@ -276,27 +276,8 @@ static char *print_string_ptr(const char *str,printbuffer *p) strcpy(out,"\"\""); return out; } - - ptr=str; -#if 0 - while ((token=*ptr) && ++len) - { - if (strchr("\"\\\b\f\n\r\t",token)) - len++; - else if (token<32) - len+=5; - ptr++; - } -#else - do { - token=*ptr; - if (strchr("\"\\\b\f\n\r\t",token)) - len++; - else if (token<32) - len+=5; - ptr++; - } while (token && ++len); -#endif + ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;} + if (p) out=ensure(p,len+3); else out=(char*)cJSON_malloc(len+3); if (!out) return 0; diff --git a/easyflash/src/ef_log.c b/easyflash/src/ef_log.c index d69affd..6d31d38 100644 --- a/easyflash/src/ef_log.c +++ b/easyflash/src/ef_log.c @@ -124,7 +124,7 @@ static SectorStatus get_sector_status(uint32_t addr) { uint32_t status_full_magic = 0, status_use_magic = 0; /* calculate the sector header address */ - header_addr = addr / EF_ERASE_MIN_SIZE * EF_ERASE_MIN_SIZE; + header_addr = addr & (~(EF_ERASE_MIN_SIZE - 1)); if (ef_port_read(header_addr, header_buf, sizeof(header_buf)) == EF_NO_ERR) { sector_header_magic = header_buf[SECTOR_HEADER_MAGIC_INDEX]; @@ -164,7 +164,7 @@ static EfErrCode write_sector_status(uint32_t addr, SectorStatus status) { uint32_t header, header_addr = 0; /* calculate the sector header address */ - header_addr = addr / EF_ERASE_MIN_SIZE * EF_ERASE_MIN_SIZE; + header_addr = addr & (~(EF_ERASE_MIN_SIZE - 1)); /* calculate the sector staus magic */ switch (status) {