summaryrefslogtreecommitdiff
path: root/tests/test_strncat_n_eq_buf.c
blob: bbc39d21a63481babb120ad09da137386dab0816 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "common.h"

#include <string.h>

int main(int argc, char** argv) {
  char buffer[8] = {0};
  strncat(buffer, "12345", 5);
  puts(buffer);

  /* n == buffer size but overflow due to existing content.
   * buffer has 5 chars, src "ABC" (len 3): 5+3+1 = 9 > 8 → overflow. */
  CHK_FAIL_START
  strncat(buffer, "ABC", 8);
  CHK_FAIL_END

  puts(buffer);
  return ret;
}