Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Jul 13, 2024
1 parent 6b39463 commit c6add2f
Show file tree
Hide file tree
Showing 4 changed files with 1,148 additions and 1,132 deletions.
57 changes: 48 additions & 9 deletions src/file.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,55 @@

/*
This code is from
The C Programming Language 2 edition, page 145
There are two bugs int this original sample
- one memory leak
- one invalid state
*/

#pragma safety enable

struct X {
int i;
#include <stdlib.h>
#include <string.h>

struct nlist { /* table entry: */
struct nlist *next; /* next entry in chain */
char *name; /* defined name */
char *defn; /* replacement text */
};

void f(struct X* _Opt p)
struct nlist *lookup(char *s);

/* hash: form hash value for string s */
unsigned hash(char *s);


#define HASHSIZE 101

static struct nlist *hashtab[HASHSIZE]; /* pointer table */

/*1* lookup: look for s in hashtab */
struct nlist *lookup(char *);


/* install: put (name, defn) in hashtab */
struct nlist *install(char *name, char *defn)
{
int i = p ? p->i : 0; //no warning

int i3 = p->i;
#pragma cake diagnostic check "-Wanalyzer-null-dereference"
struct nlist *np;
unsigned hashval;

if ((np = lookup(name)) == NULL) { /* not found */
np = (struct nlist *) malloc(sizeof(*np));
if (np == NULL || (np->name = strdup(name)) == NULL)
return NULL;
hashval = hash(name);
np->next = hashtab[hashval];
hashtab[hashval] = np;
} else /* already there */
free((void *) np->defn); /* free previous defn */

int i2 = p ? 0 : p->i; //warning
#pragma cake diagnostic check "-Wanalyzer-null-dereference"
if ((np->defn = strdup(defn)) == NULL)
return NULL;
return np;
}
29 changes: 12 additions & 17 deletions src/flow_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1891,10 +1891,7 @@ void object_get_name_core(
}
else
{
if (type_is_pointer(p_type))
{
snprintf(outname, out_size, "%s", previous_names);
}
snprintf(outname, out_size, "%s", previous_names);
}
}

Expand Down Expand Up @@ -1943,8 +1940,6 @@ void object_get_name(const struct type* p_type,
outname[0] = '?';
outname[1] = '\0';
}

assert(outname[0] != '\0');
}

void checked_moved_core(struct flow_visit_ctx* ctx,
Expand Down Expand Up @@ -2011,11 +2006,11 @@ void checked_moved_core(struct flow_visit_ctx* ctx,
p_object->current.ref.data[i],
position_token,
visit_number);
}
}
#endif
type_destroy(&t2);
}
}
}
}

if (p_object->current.state & OBJECT_STATE_MOVED)
{
Expand Down Expand Up @@ -2251,10 +2246,10 @@ void checked_read_object(struct flow_visit_ctx* ctx,
bool check_pointed_object)
{
const char* _Owner _Opt s = NULL;
char name[200] = {0};
object_get_name(p_type, p_object, name, sizeof name);
char name[200] = { 0 };

object_get_name(p_type, p_object, name, sizeof name);

struct object_visitor visitor = { 0 };
visitor.p_object = p_object;
visitor.p_type = p_type;
Expand Down Expand Up @@ -2724,7 +2719,7 @@ static void flow_assignment_core(


return;
}
}



Expand Down Expand Up @@ -3212,11 +3207,11 @@ struct flow_object* _Opt expression_get_object(struct flow_visit_ctx* ctx, stru
}
}
return p_object;
}
#endif
}
return NULL;
#endif
}
return NULL;
}
else if (p_expression->expression_type == UNARY_EXPRESSION_CONTENT)
{
struct flow_object* _Opt p_obj = expression_get_object(ctx, p_expression->right, nullable_enabled);
Expand Down
29 changes: 12 additions & 17 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -23858,10 +23858,7 @@ void object_get_name_core(
}
else
{
if (type_is_pointer(p_type))
{
snprintf(outname, out_size, "%s", previous_names);
}
snprintf(outname, out_size, "%s", previous_names);
}
}

Expand Down Expand Up @@ -23910,8 +23907,6 @@ void object_get_name(const struct type* p_type,
outname[0] = '?';
outname[1] = '\0';
}

assert(outname[0] != '\0');
}

void checked_moved_core(struct flow_visit_ctx* ctx,
Expand Down Expand Up @@ -23978,11 +23973,11 @@ void checked_moved_core(struct flow_visit_ctx* ctx,
p_object->current.ref.data[i],
position_token,
visit_number);
}
}
#endif
type_destroy(&t2);
}
}
}
}

if (p_object->current.state & OBJECT_STATE_MOVED)
{
Expand Down Expand Up @@ -24218,10 +24213,10 @@ void checked_read_object(struct flow_visit_ctx* ctx,
bool check_pointed_object)
{
const char* _Owner _Opt s = NULL;
char name[200] = {0};
object_get_name(p_type, p_object, name, sizeof name);
char name[200] = { 0 };

object_get_name(p_type, p_object, name, sizeof name);

struct object_visitor visitor = { 0 };
visitor.p_object = p_object;
visitor.p_type = p_type;
Expand Down Expand Up @@ -24691,7 +24686,7 @@ static void flow_assignment_core(


return;
}
}



Expand Down Expand Up @@ -25179,11 +25174,11 @@ struct flow_object* _Opt expression_get_object(struct flow_visit_ctx* ctx, stru
}
}
return p_object;
}
#endif
}
return NULL;
#endif
}
return NULL;
}
else if (p_expression->expression_type == UNARY_EXPRESSION_CONTENT)
{
struct flow_object* _Opt p_obj = expression_get_object(ctx, p_expression->right, nullable_enabled);
Expand Down
2,165 changes: 1,076 additions & 1,089 deletions src/web/cake.js

Large diffs are not rendered by default.

0 comments on commit c6add2f

Please sign in to comment.