/* Null pointers comparison */
s = 0;
indicator = clib_strcmp (s, s);
- if (indicator != 0)
- return -1;
- /* verify it against strcmp */
- indicator = strcmp (s, s);
if (indicator != 0)
return -1;
sizeof ("Every moment is a fresh beginning") - 1);
if (v_indicator != 0)
return -1;
- if (v_indicator != indicator)
- return -1;
/* OK, seems to work */
return 0;
return -1;
/* overlap fail */
+#if __GNUC__ < 8
+ /* GCC 8 flunks this one at compile time... */
err = strcpy_s (dst, s1size, dst);
if (err == EOK)
return -1;
+#endif
/* overlap fail */
err = strcpy_s (dst, s1size, dst + 1);
return -1;
/* overlap fail */
+#if __GNUC__ < 8
+ /* GCC 8 flunks this one at compile time... */
err = clib_strcpy (dst, dst);
if (err == EOK)
return -1;
+#endif
/* overlap fail */
err = clib_strcpy (dst, dst + 1);
{
char src[] = "Those who dare to fail miserably can achieve greatly.";
char dst[100], old_dst[100];
- int indicator;
+ int indicator, i;
size_t s1size = sizeof (dst); // including null
errno_t err;
return -1;
/* n > string len of src */
+ err = clib_memset (dst, 1, sizeof (dst));
+ if (err != EOK)
+ return -1;
+
err = strncpy_s (dst, s1size, src, clib_strnlen (src, sizeof (src)) + 10);
if (err != EOK)
return -1;
if (indicator != 0)
return -1;
+ /* Make sure bytes after strlen(dst) is untouched */
+ for (i = 1 + clib_strnlen (dst, sizeof (dst)); i < sizeof (dst); i++)
+ if (dst[i] != 1)
+ return -1;
+
/* truncation, n >= dmax */
err = strncpy_s (dst, clib_strnlen (src, sizeof (src)), src,
clib_strnlen (src, sizeof (src)));
return -1;
/* overlap fail */
+#if __GNUC__ < 8
+ /* GCC 8 flunks this one at compile time... */
err = strncpy_s (dst, s1size, dst, s1size);
if (err == EOK)
return -1;
+#endif
/* OK, seems to work */
return 0;
return -1;
/* Verify it against strncpy */
+#if __GNUC__ < 8
+ /* GCC 8 debian flunks this one at compile time */
strncpy (dst, src, strlen (src));
/* This better not fail but check anyhow */
return -1;
if (indicator != 0)
return -1;
+#endif
/* limited copy -- strlen src > n, copy up to n */
err = clib_strncpy (dst, "The price of greatness is responsibility.", 10);
return -1;
/* verify it against strncpy */
memset_s (dst, sizeof (dst), 0, sizeof (dst));
+
+#if __GNUC__ < 8
+ /* GCC 8 flunks this one at compile time... */
strncpy (dst, "The price of greatness is responsibility.", 10);
if (strcmp_s (dst, clib_strnlen (dst, sizeof (dst)), "The price ",
&indicator) != EOK)
return -1;
if (indicator != 0)
return -1;
+#endif
/* n > string len of src */
err = clib_strncpy (dst, src, clib_strnlen (src, sizeof (src)) + 10);
if (indicator != 0)
return -1;
/* Verify it against strncpy */
+#if __GNUC__ < 8
+ /* GCC 8 debian flunks this one at compile time */
strncpy (dst, src, strlen (src));
if (strcmp_s (dst, clib_strnlen (dst, sizeof (dst)), src, &indicator) !=
EOK)
return -1;
if (indicator != 0)
return -1;
+#endif
/* zero length copy */
clib_strncpy (old_dst, dst, clib_strnlen (dst, sizeof (dst)));
return -1;
/* overlap fail */
+#if __GNUC__ < 8
+ /* GCC 8 flunks this one at compile time... */
err = clib_strncpy (dst, dst, s1size);
if (err == EOK)
return -1;
+#endif
/* OK, seems to work */
return 0;
return -1;
/* overlap fail */
+#if __GNUC__ < 8
+ /* GCC 8 flunks this one at compile time... */
err = strcat_s (dst, s1size, dst);
if (err != EINVAL)
return -1;
+#endif
/* not enough space for dst */
err = strcat_s (dst, 10, src);
return -1;
/* overlap fail */
+#if __GNUC__ < 8
+ /* GCC 8 flunks this one at compile time... */
err = clib_strcat (dst, dst);
if (err != EINVAL)
return -1;
+#endif
/* OK, seems to work */
return 0;
if (indicator != 0)
return -1;
/* verify it against strncat */
+#if __GNUC__ < 8
+ /* GCC 8 debian flunks this one at compile time */
strcpy_s (dst, sizeof (dst), s1);
strncat (dst, s2, 13);
if (strcmp_s (dst, s1size - 1, "Two things are infinite: the universe ",
return -1;
if (indicator != 0)
return -1;
+#endif
/* negative stuff */
err = strncat_s (0, 0, 0, 1);
return -1;
/* overlap fail */
+#if __GNUC__ < 8
+ /* GCC 8 flunks this one at compile time... */
err = strncat_s (dst, s1size, dst, clib_strnlen (dst, sizeof (dst)));
if (err != EINVAL)
return -1;
+#endif
/* OK, seems to work */
return 0;
if (indicator != 0)
return -1;
/* verify it against strncat */
+#if __GNUC__ < 8
+ /* GCC 8 debian flunks this one at compile time */
strcpy_s (dst, sizeof (dst), s1);
strncat (dst, s2, 13);
if (strcmp_s (dst, s1size - 1, "Two things are infinite: the universe ",
return -1;
if (indicator != 0)
return -1;
+#endif
/* negative stuff */
err = clib_strncat (0, 0, 1);
return -1;
/* overlap fail */
+#if __GNUC__ < 8
+ /* GCC 8 flunks this one at compile time... */
err = clib_strncat (dst, dst, clib_strnlen (dst, sizeof (dst)));
if (err != EINVAL)
return -1;
+#endif
/* OK, seems to work */
return 0;
test_clib_strtok (vlib_main_t * vm, unformat_input_t * input)
{
int indicator;
- char *tok, *ptr, *s1;
+ char *s1 __attribute__ ((unused));
+ char *tok __attribute__ ((unused));
+ char *ptr __attribute__ ((unused));
char str1[40];
char *p2str;
char *tok1, *tok2, *tok3, *tok4, *tok5, *tok6, *tok7;
/* negative stuff */
s1 = 0;
ptr = 0;
+#if __GNUC__ < 8
+ /* GCC 8 flunks this one at compile time... */
tok = clib_strtok (s1, s1, (char **) 0);
if (tok != 0)
return -1;
tok = clib_strtok (s1, s1, &ptr);
if (tok != 0)
return -1;
+#endif
+
/* verify it against strtok_r */
/* No can do. This causes a crash in strtok_r */
// tok = strtok_r (s1, " ", &ptr);