Repair allocation size, bounds and deallocation base

The fragment below follows a valid size_t n read. Identify EVERY independent defect or portability assumption. Repair it as a full program that reads n in 0..20 and n representable ints, prints them in reverse order on one line, and frees correctly. Handle empty input, conversion failure, allocation failure and size multiplication overflow. Do not claim that sizeof a is always too small or that any invalid original run has a specified output.

int *a = malloc(n * sizeof a);
for (size_t i = 0; i <= n; ++i) scanf("%d", &a[i]);
free(a + 1);

