Forked from
Prevosto Virgile / AnaStat-Frama-C-24-25
8 commits behind, 4 commits ahead of the upstream repository.
-
Bachir Lachguel authoredBachir Lachguel authored
cwe20_compliant.c 1006 B
#include <stdio.h>
#include <stdlib.h>
void die(const char *s) {
printf("%s", s);
exit(2);
}
#define MAX_DIM 15
typedef int board_square_t;
/* board dimensions */
int main(void) {
unsigned int m, n, error;
board_square_t *board;
printf("Please specify the board height: \n");
error = scanf("%d", &m);
if (EOF == error) {
die("No integer passed: Die evil hacker!\n");
}
printf("Please specify the board width: \n");
error = scanf("%d", &n);
if (EOF == error) {
die("No integer passed: Die evil hacker!\n");
}
if (m > MAX_DIM || m <= 0 || n > MAX_DIM) {
die("Value too large: Die evil hacker!\n");
}
board = (board_square_t *)malloc(m * n * sizeof(board_square_t));
// Check that is memory is properly allocated
if (!board) {
return 2;
}
for (unsigned int i = 0; i < m; i++) {
for (unsigned int j = 0; j < n; j++) {
board[n * i + j] = 0;
}
}
//@ split m == 0;
if (board[(m - 1) * n] == 0)
return 0;
else
return 1;
}