Browse Source

fix two complaints by clang's static analyzer

master
Felix von Leitner 1 month ago
parent
commit
d9d7a26770
2 changed files with 9 additions and 4 deletions
  1. +6
    -2
      ent.c
  2. +3
    -2
      textcode/scan_jsonescape.c

+ 6
- 2
ent.c View File

@@ -128,8 +128,12 @@ void marshalhelper(struct letters* s) {

void marshal(struct letters* s) {
fprintf(stderr,"nodes=%zu, datasize=%zu\n",nodes,datasize);
heap=malloc((nodes+1)*sizeof(uint32_t)+datasize);
if (!heap) nomem();
{
size_t l;
heap=malloc(l=(nodes+1)*sizeof(uint32_t)+datasize);
if (!heap) nomem();
memset(heap,0,l);
}
marshaled=(uint32_t*)heap;
marshaled[0]=nodes+1;
data=heap+(nodes+1)*sizeof(uint32_t);


+ 3
- 2
textcode/scan_jsonescape.c View File

@@ -6,8 +6,8 @@ size_t scan_jsonescape(const char *src,char *dest,size_t *destlen) {
register const unsigned char* s=(const unsigned char*) src;
size_t written=0,i;
char c;
unsigned int prev,cur,todo;
prev=cur=(unsigned int)-1;
unsigned int prev,todo;
prev=(unsigned int)-1;
for (i=0; s[i]; ++i) {
if (s[i]=='"') {
if (prev!=(unsigned int)-1) goto abort;
@@ -27,6 +27,7 @@ size_t scan_jsonescape(const char *src,char *dest,size_t *destlen) {
case 'u':
{
size_t j;
unsigned int cur;
for (cur=j=0; j<4; ++j) {
char x=scan_fromhex(s[i+2+j]);
if (x<0) goto abort; // not hex -> invalid input


Loading…
Cancel
Save