Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fixdep: use xmalloc()

When malloc() fails, there is not much userspace programs can do.
xmalloc() is useful to bail out on a memory allocation failure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+5 -10
+5 -10
scripts/basic/fixdep.c
··· 99 99 #include <stdio.h> 100 100 #include <ctype.h> 101 101 102 + #include <xalloc.h> 103 + 102 104 static void usage(void) 103 105 { 104 106 fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n"); ··· 133 131 static void add_to_hashtable(const char *name, int len, unsigned int hash, 134 132 struct item *hashtab[]) 135 133 { 136 - struct item *aux = malloc(sizeof(*aux) + len); 134 + struct item *aux; 137 135 138 - if (!aux) { 139 - perror("fixdep:malloc"); 140 - exit(1); 141 - } 136 + aux = xmalloc(sizeof(*aux) + len); 142 137 memcpy(aux->name, name, len); 143 138 aux->len = len; 144 139 aux->hash = hash; ··· 227 228 perror(filename); 228 229 exit(2); 229 230 } 230 - buf = malloc(st.st_size + 1); 231 - if (!buf) { 232 - perror("fixdep: malloc"); 233 - exit(2); 234 - } 231 + buf = xmalloc(st.st_size + 1); 235 232 if (read(fd, buf, st.st_size) != st.st_size) { 236 233 perror("fixdep: read"); 237 234 exit(2);