Deutsch English Français Italiano |
<v558hv$3dskb$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Lawrence D'Oliveiro <ldo@nz.invalid> Newsgroups: comp.lang.c Subject: Re: Fixing a sample from K&R book using cake static analyser Date: Sat, 22 Jun 2024 01:14:40 -0000 (UTC) Organization: A noiseless patient Spider Lines: 56 Message-ID: <v558hv$3dskb$1@dont-email.me> References: <v53sl1$35qt7$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sat, 22 Jun 2024 03:14:40 +0200 (CEST) Injection-Info: dont-email.me; posting-host="e2ad63ef29eb171d8254bd46738c313e"; logging-data="3601035"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qpz9cN6DVM2Ve6ZhakHcv" User-Agent: Pan/0.158 (Avdiivka; ) Cancel-Lock: sha1:VR7xfZjY8Fgoyk4tcvFfzk1woFo= Bytes: 2657 On Fri, 21 Jun 2024 09:45:21 -0300, Thiago Adams wrote: > Page 145, The C programming Language 2 Edition > > /* install: put (name, defn) in hashtab */ > struct nlist *install(char *name, char *defn) > { > 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 */ > > if ((np->defn = strdup(defn)) == NULL) > return NULL; > return np; > } struct nlist *install(char *name, char *defn) { struct nlist *np = NULL; struct nlist *result = NULL; unsigned hashval; do /*once*/ { result = lookup(name); if (result != NULL) break; np = (struct nlist *)calloc(1, sizeof struct nlist); if (np == NULL) break; np->defn = strdup(defn); if (np->defn == NULL) break; hashval = hash(name); np->next = hashtab[hashval]; hashtab[hashval] = np; result = np; np = NULL; /* so I don’t dispose of it yet */ } while (false); if (np != NULL) { free(np->defn); } /*if*/ free(np); return result; } /*install*/