X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=misc.c;h=45528c20dd2e7485a4c93c85964ea19bbf0e6497;hb=aca6d79087dc9ef6f9f1b4e1d2ef0d25d405db9b;hp=f05e51883c5e55dbab1a323f73e15cca6149e2b5;hpb=1e643da216737e148839f463c10594bbb8ac246b;p=open-adventure.git diff --git a/misc.c b/misc.c index f05e518..45528c2 100644 --- a/misc.c +++ b/misc.c @@ -15,8 +15,11 @@ void* xmalloc(size_t size) { void* ptr = malloc(size); if (ptr == NULL) { + // LCOV_EXCL_START + // exclude from coverage analysis because we can't simulate an out of memory error in testing fprintf(stderr, "Out of memory!\n"); exit(EXIT_FAILURE); + // LCOV_EXCL_STOP } return (ptr); } @@ -249,7 +252,10 @@ char* get_input() input = NULL; size_t n = 0; if (isatty(0)) + // LCOV_EXCL_START + // Should be unreachable in tests, as they will use a non-interactive shell. printf("%s", input_prompt); + // LCOV_EXCL_STOP IGNORE(getline(&input, &n, stdin)); } @@ -286,10 +292,13 @@ bool yes(const char* question, const char* yes_response, const char* no_response speak(question); reply = get_input(); - if (reply == NULL) { - linenoiseFree(reply); - exit(EXIT_SUCCESS); - } + if (reply == NULL) { + // LCOV_EXCL_START + // Should be unreachable. Reply should never be NULL + linenoiseFree(reply); + exit(EXIT_SUCCESS); + // LCOV_EXCL_STOP + } char* firstword = (char*) xmalloc(strlen(reply)+1); sscanf(reply, "%s", firstword); @@ -408,7 +417,7 @@ long vocab(long id, long init) lexeme = -1; if (init < 0) return (lexeme); - BUG(REQUIRED_VOCABULARY_WORD_NOT_FOUND); + BUG(REQUIRED_VOCABULARY_WORD_NOT_FOUND); // LCOV_EXCL_LINE } if (init >= 0 && KTAB[i] / 1000 != init) continue; @@ -419,7 +428,7 @@ long vocab(long id, long init) return (lexeme); } } - BUG(RAN_OFF_END_OF_VOCABULARY_TABLE); + BUG(RAN_OFF_END_OF_VOCABULARY_TABLE); // LCOV_EXCL_LINE } void juggle(long object) @@ -526,7 +535,7 @@ long atdwrf(long where) long setbit(long bit) /* Returns 2**bit for use in constructing bit-masks. */ { - return (1 << bit); + return (1L << bit); } bool tstbit(long mask, int bit) @@ -687,10 +696,12 @@ void datime(long* d, long* t) *t = (long) tv.tv_usec; } +// LCOV_EXCL_START void bug(enum bugtype num, const char *error_string) { fprintf(stderr, "Fatal error %d, %s.\n", num, error_string); exit(EXIT_FAILURE); } +// LCOV_EXCL_STOP /* end */