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

#include <string.h>

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

  /* n=4 is less than buffer size (8), but buffer already has 5 chars,
   * so appending 4 more + NUL = 10 bytes total, overflowing the buffer.
   */
  CHK_FAIL_START
  strncat(buffer, "ABCD", 4);
  CHK_FAIL_END

  puts(buffer);
  return ret;
}