[PATCH] psxhdrs_strncpy_fix string_turncation_warning

Aschref Ben-Thabet aschref.ben-thabet at embedded-brains.de
Wed Aug 5 09:07:26 UTC 2020


From: Aschref Ben Thabet <aschref.ben-thabet at embedded-brains.de>

since we need to test the strncpy function, using a character array with
a fixed array size in this case in place of character pointer can avoid
the string turncation warning.
---
 testsuites/psxtests/psxhdrs/string/stpncpy.c | 8 ++++----
 testsuites/psxtests/psxhdrs/string/strncpy.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/testsuites/psxtests/psxhdrs/string/stpncpy.c b/testsuites/psxtests/psxhdrs/string/stpncpy.c
index f81752de76..8b3abf747e 100644
--- a/testsuites/psxtests/psxhdrs/string/stpncpy.c
+++ b/testsuites/psxtests/psxhdrs/string/stpncpy.c
@@ -35,17 +35,17 @@
  #endif
 
  #include <string.h>
+ #define size 1024
 
  int test( void );
 
  int test( void )
  {
-   char *dest = "Hello world";
-   char *src = "Dude";
-   size_t num = 2;
+   char dest[size] = "Hello world";
+   char src[size] = "Dude";
    char *result;
 
-   result = stpncpy( dest, src, num );
+   result = stpncpy( dest, src, sizeof(dest) );
 
    return ( result != NULL );
  }
diff --git a/testsuites/psxtests/psxhdrs/string/strncpy.c b/testsuites/psxtests/psxhdrs/string/strncpy.c
index 50b64b3d57..73bc480b58 100644
--- a/testsuites/psxtests/psxhdrs/string/strncpy.c
+++ b/testsuites/psxtests/psxhdrs/string/strncpy.c
@@ -35,16 +35,16 @@
  #endif
 
  #include <string.h>
-
+ #define size 1024
  int test( void );
 
  int test( void )
  {
-   char *dest = "Hello";
-   char *src = "World";
+   char dest[size] = "Hello";
+   char src[size] = "World";
    char *result;
 
-   result = strncpy( dest, src, 3 );
+   result = strncpy( dest, src, sizeof(dest) );
 
    return ( result != NULL );
  }
-- 
2.26.2



More information about the devel mailing list