Multiple choice

void * array_dup (a, number, size) const void * a; size_t number; size_t size; { void * clone; size_t bytes; assert(a != NULL); bytes = number * size; clone = alloca(bytes); if (!clone) return clone; memcpy(clone, a, bytes); return clone; }

The function array_dup(), defined above, contains an error. Which of the following options correctly analyses it?

  1. If the arguments to memcpy() refer to overlapping regions, the destination buffer will be subject to memory corruption.

  2. Array_dup() declares its first parameter to be a pointer, when the actual argument will be an array.

  3. The memory obtained from alloca() is not valid in the context of the caller. Moreover, alloca() is non-standard.

  4. Size_t is not a standard C defined type, and may not be kn.

  5. The definition of array_dup() is unusual. Functions cannot be defined using this syntax.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Option (1) is correct.