...
Code Block | ||
---|---|---|
| ||
#include <stdlib.h> #include <stdio.h> enum { MAXLINE = 1000 }; size_t calc() { char line[MAXLINE], c; size_t size = 0; while ( (c = getchar()) != EOF && c != '\n') { line[size] = c; size++; if (size >= MAXLINE) break; } return size; } int main(void) { size_t size = calc(); if (!size) { /* Handle invalid size */ } char * line = malloc(size) /* ... */ free(line); } |
Risk Assessment
Calling a function with incorrect arguments can result in unexpected or unintended program behavior.
...