Multiple choice technology security

What is the vulnerability ?

int main (int argc, char *argv[]) { 
     char k[3]; 
     int i=0,j=1; 
     char buffer[50]; 
     strncpy(buffer, argv[1], sizeof(buffer) - 1); 
     buffer[49]='/0'; 
     unsigned char ch='a'; 
     k[0]=1; 
     do{   
        i++;   
        k[i]=ch+i; 
    } while(i<3); 

    return 0; 
}  

  1. Heap overflow

  2. Integer overflow

  3. Off by one error

  4. None of the above

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

The loop condition is i < 3 but i starts at 0 and is incremented before the array write: i++ makes i=1 in the first iteration (writing to k[1]), then i=2 (k[2]), and i=3 (k[3]). Since k has size 3, writing to index 3 is an off-by-one out-of-bounds write.