diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-11-10 22:24:10 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-11-10 22:24:10 +1300 |
commit | a6d51ece9ed6bfb6b26aeedf61ec38f07725aac1 (patch) | |
tree | 8c5c97e6dce8d1406ec6fb5cee9215b2b17b922c | |
parent | Remove bad-practice malloc(3) casts (diff) | |
download | texad-a6d51ece9ed6bfb6b26aeedf61ec38f07725aac1.tar.gz texad-a6d51ece9ed6bfb6b26aeedf61ec38f07725aac1.zip |
Use adaptive sizeof on identifiers not types
-rw-r--r-- | texad.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -74,14 +74,14 @@ struct world *genesis(void) unsigned int i; - w = malloc(sizeof(struct world)); - p = malloc(sizeof(struct player)); + w = malloc(sizeof *w); + p = malloc(sizeof *p); - for (i = 0; i < sizeof(r) / sizeof(struct room*); i++) { - r[i] = (struct room*) malloc(sizeof(struct room)); + for (i = 0; i < sizeof r / sizeof r[0]; i++) { + r[i] = malloc(sizeof r[0]); } - for (i = 0; i < sizeof(d) / sizeof(struct door*); i++) { - d[i] = (struct door*) malloc(sizeof(struct door)); + for (i = 0; i < sizeof d / sizeof d[0]; i++) { + d[i] = malloc(sizeof d[0]); } r[0]->title = "The foo room"; @@ -167,7 +167,7 @@ enum action parse(char *s) { unsigned long i; s[strcspn(s, "\n")] = 0; - for (i = 0; i < sizeof(commands) / sizeof(struct command); i++) + for (i = 0; i < sizeof commands / sizeof commands[0]; i++) if (commands[i].string && !strcmp(commands[i].string, s)) return commands[i].action; return UNKNOWN; |