[PATCH] tests: Avoid printf versions that uses floats

Daniel Hellstrom daniel at gaisler.com
Wed Sep 19 14:13:24 UTC 2018


From: Daniel Cederman <cederman at gaisler.com>

---
 testsuites/fstests/fserror/test.c        |  8 +++---
 testsuites/fstests/fspermission/test.c   |  2 +-
 testsuites/fstests/fsrename/test.c       | 44 ++++++++++++++++----------------
 testsuites/libtests/block06/init.c       |  4 +--
 testsuites/psxtests/psxfile01/test.c     |  2 +-
 testsuites/psxtests/psximfs02/init.c     |  6 ++---
 testsuites/psxtests/psxpasswd02/init.c   | 16 ++++++------
 testsuites/psxtests/psxstat/test.c       |  6 ++---
 testsuites/smptests/smp03/tasks.c        |  2 +-
 testsuites/smptests/smp08/init.c         |  2 +-
 testsuites/smptests/smpaffinity01/init.c |  4 +--
 11 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/testsuites/fstests/fserror/test.c b/testsuites/fstests/fserror/test.c
index c53aff8..123b96c 100644
--- a/testsuites/fstests/fserror/test.c
+++ b/testsuites/fstests/fserror/test.c
@@ -78,7 +78,7 @@ static void open_mkdir_error (void)
    * the path argument points to an empty string.
    */
 
-  sprintf (name, "%s/%s", name03, name02);
+  siprintf (name, "%s/%s", name03, name02);
   EXPECT_ERROR (ENOENT, open, name, O_WRONLY);
   EXPECT_ERROR (ENOENT, open, "", O_WRONLY);
   EXPECT_ERROR (ENOENT, open, name03, O_WRONLY);
@@ -90,7 +90,7 @@ static void open_mkdir_error (void)
    * A component of the path prefix is not a directory.
    */
 
-  sprintf (name, "%s/%s", name01, name02);
+  siprintf (name, "%s/%s", name01, name02);
   EXPECT_ERROR (ENOTDIR, open, name, O_WRONLY);
 
   EXPECT_ERROR (ENOTDIR, mkdir, name, mode);
@@ -141,7 +141,7 @@ static void rename_error (void)
   rtems_test_assert (status == 0);
   status = mkdir (name02, mode);
   rtems_test_assert (status == 0);
-  sprintf (name, "%s/%s", name01, name03);
+  siprintf (name, "%s/%s", name01, name03);
   status = mkdir (name, mode);
   rtems_test_assert (status == 0);
 
@@ -181,7 +181,7 @@ static void rename_error (void)
    *  a non-directory file.
    */
 
-  sprintf (name, "%s/%s", name03, name01);
+  siprintf (name, "%s/%s", name03, name01);
   EXPECT_ERROR (ENOTDIR, rename, name, name03);
   EXPECT_ERROR (ENOTDIR, rename, name03, name);
   EXPECT_ERROR (ENOTDIR, rename, name02, name03);
diff --git a/testsuites/fstests/fspermission/test.c b/testsuites/fstests/fspermission/test.c
index 36675ac..c4a1864 100644
--- a/testsuites/fstests/fspermission/test.c
+++ b/testsuites/fstests/fspermission/test.c
@@ -244,7 +244,7 @@ static void test_premission01(void )
 
   status=mkdir(directory01,0777);
   rtems_test_assert(status==0);
-  sprintf(path,"%s/%s",directory01,file01);
+  siprintf(path,"%s/%s",directory01,file01);
   fd = creat(path,0777);
   rtems_test_assert(fd >= 0);
   status = close(fd);
diff --git a/testsuites/fstests/fsrename/test.c b/testsuites/fstests/fsrename/test.c
index 6799ab4..93a4901 100644
--- a/testsuites/fstests/fsrename/test.c
+++ b/testsuites/fstests/fsrename/test.c
@@ -144,11 +144,11 @@ static void symbolic_link_test (void)
   status = symlink (symlink02, symlink01);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/test", symlink01);
+  rv = sniprintf (path01, sizeof(path01), "%s/test", symlink01);
   rtems_test_assert (rv < sizeof(path01));
   EXPECT_ERROR (ELOOP, rename, path01, name01);
 
-  rv = snprintf (path01, sizeof(path01), "%s/test", symlink02);
+  rv = sniprintf (path01, sizeof(path01), "%s/test", symlink02);
   rtems_test_assert (rv < sizeof(path01));
   EXPECT_ERROR (ELOOP, rename, path01, name01);
 
@@ -177,11 +177,11 @@ static void symbolic_link_test (void)
   status = symlink (symlink02, symlink01);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/test", symlink01);
+  rv = sniprintf (path01, sizeof(path01), "%s/test", symlink01);
   rtems_test_assert (rv < sizeof(path01));
   EXPECT_ERROR (ELOOP, rename, name01, path01);
 
-  rv = snprintf (path01, sizeof(path01), "%s/test", symlink02);
+  rv = sniprintf (path01, sizeof(path01), "%s/test", symlink02);
   rtems_test_assert (rv < sizeof(path01));
   EXPECT_ERROR (ELOOP, rename, name01, path01);
 
@@ -268,7 +268,7 @@ static void same_file_test (void)
   status = mkdir (dir01, mode);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name02);
+  rv = sniprintf (path01, sizeof(path01), "%s/%s", dir01, name02);
   rtems_test_assert (rv < sizeof(path01));
   status = link (name01, path01);
   rtems_test_assert (status == 0);
@@ -389,7 +389,7 @@ static void directory_test (void)
   status = mkdir (dir02, mode);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/%s", dir02, dir01);
+  rv = sniprintf (path01, sizeof(path01), "%s/%s", dir02, dir01);
   rtems_test_assert (rv < sizeof(path01));
   status = mkdir (path01, mode);
   rtems_test_assert (status == 0);
@@ -416,7 +416,7 @@ static void directory_test (void)
   status = mkdir (dir02, mode);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/%s", dir02, name02);
+  rv = sniprintf (path01, sizeof(path01), "%s/%s", dir02, name02);
   rtems_test_assert (rv < sizeof(path01));
   fd = creat (path01, mode);
   rtems_test_assert (fd >= 0);
@@ -478,7 +478,7 @@ static void directory_test (void)
 
   for(i = statbuf.st_nlink; i < LINK_MAX_val; i++)
   {
-    rv = snprintf (link_name, sizeof(link_name), "%s/%d", dir01, i);
+    rv = sniprintf (link_name, sizeof(link_name), "%s/%d", dir01, i);
     rtems_test_assert (rv < sizeof(link_name));
 
     status = mkdir (link_name, mode);
@@ -488,7 +488,7 @@ static void directory_test (void)
   status = mkdir (dir02, mode);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, dir01);
+  rv = sniprintf (path01, sizeof(path01), "%s/%s", dir01, dir01);
   rtems_test_assert (rv < sizeof(path01));
   EXPECT_ERROR (EMLINK, rename, dir02, path01);
 
@@ -498,7 +498,7 @@ static void directory_test (void)
 
   for(i = statbuf.st_nlink; i < LINK_MAX_val; i++)
   {
-    rv = snprintf (link_name, sizeof(link_name), "%s/%d", dir01, i);
+    rv = sniprintf (link_name, sizeof(link_name), "%s/%d", dir01, i);
     rtems_test_assert (rv < sizeof(link_name));
 
     status = rmdir (link_name);
@@ -519,7 +519,7 @@ static void directory_test (void)
   status = mkdir (dir01, mode | S_ISVTX);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name01);
+  rv = sniprintf (path01, sizeof(path01), "%s/%s", dir01, name01);
   rtems_test_assert (rv < sizeof(path01));
   fd = creat (path01, mode);
   rtems_test_assert (fd >= 0);
@@ -562,7 +562,7 @@ static void directory_test (void)
   status = mkdir (dir01, mode | S_ISVTX);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name01);
+  rv = sniprintf (path01, sizeof(path01), "%s/%s", dir01, name01);
   rtems_test_assert (rv < sizeof(path01));
   fd = creat (path01, mode);
   rtems_test_assert (fd >= 0);
@@ -690,7 +690,7 @@ static void arg_test (void)
   status = mkdir (dir01, mode);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/%s/%s", dir01, name01, name02);
+  rv = sniprintf (path01, sizeof(path01), "%s/%s/%s", dir01, name01, name02);
   rtems_test_assert (rv < sizeof(path01));
   EXPECT_ERROR (ENOENT, rename, path01, name01);
 
@@ -981,7 +981,7 @@ static void write_permission_test (void)
   status = close (fd);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "../%s/%s", dir01, name02);
+  rv = sniprintf (path01, sizeof(path01), "../%s/%s", dir01, name02);
   rtems_test_assert (rv < sizeof(path01));
   EXPECT_ERROR (EACCES, rename, name01, path01);
 
@@ -998,16 +998,16 @@ static void write_permission_test (void)
 
   EXPECT_EQUAL (0, unlink, name01);
 
-  rv = snprintf (path01, sizeof(path01), "../%s", dir01);
+  rv = sniprintf (path01, sizeof(path01), "../%s", dir01);
   rtems_test_assert (rv < sizeof(path01));
   status = chmod (path01, mode);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "../%s/%s", dir01, name01);
+  rv = sniprintf (path01, sizeof(path01), "../%s/%s", dir01, name01);
   rtems_test_assert (rv < sizeof(path01));
   EXPECT_EQUAL (0, unlink, path01);
 
-  rv = snprintf (path01, sizeof(path01), "../%s/%s", dir01, name02);
+  rv = sniprintf (path01, sizeof(path01), "../%s/%s", dir01, name02);
   rtems_test_assert (rv < sizeof(path01));
   EXPECT_EQUAL (0, unlink, path01);
 
@@ -1073,14 +1073,14 @@ static void search_permission_test (void)
   status = mkdir (dir01, mode);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name01);
+  rv = sniprintf (path01, sizeof(path01), "%s/%s", dir01, name01);
   rtems_test_assert (rv < sizeof(path01));
   fd = creat (path01, mode);
   rtems_test_assert (fd >= 0);
   status = close (fd);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path02, sizeof(path02), "%s/%s", dir01, name02);
+  rv = sniprintf (path02, sizeof(path02), "%s/%s", dir01, name02);
   rtems_test_assert (rv < sizeof(path02));
   fd = creat (path02, mode);
   rtems_test_assert (fd >= 0);
@@ -1113,7 +1113,7 @@ static void search_permission_test (void)
   status = chdir ("..");
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/%s", dir02, name01);
+  rv = sniprintf (path01, sizeof(path01), "%s/%s", dir02, name01);
   rtems_test_assert (rv < sizeof(path01));
   EXPECT_ERROR (EACCES, rename, path01, path02);
 
@@ -1133,7 +1133,7 @@ static void search_permission_test (void)
   status = chmod (dir01, mode);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name01);
+  rv = sniprintf (path01, sizeof(path01), "%s/%s", dir01, name01);
   rtems_test_assert (rv < sizeof(path01));
   EXPECT_EQUAL (0, unlink, path01);
   EXPECT_EQUAL (0, unlink, path02);
@@ -1193,7 +1193,7 @@ static void filesystem_test (void)
   status = close (fd);
   rtems_test_assert (status == 0);
 
-  rv = snprintf (path01, sizeof(path01), "%s/%s", BASE_FOR_TEST, name02);
+  rv = sniprintf (path01, sizeof(path01), "%s/%s", BASE_FOR_TEST, name02);
   rtems_test_assert (rv < sizeof(path01));
   EXPECT_ERROR (EXDEV, rename, name01, path01);
 
diff --git a/testsuites/libtests/block06/init.c b/testsuites/libtests/block06/init.c
index 7c6facf..fb43900 100644
--- a/testsuites/libtests/block06/init.c
+++ b/testsuites/libtests/block06/init.c
@@ -332,7 +332,7 @@ bdbuf_task_control_init (int                       task,
                          rtems_id                  master)
 {
   char name[6];
-  sprintf (name, "bdt%d", task);
+  siprintf (name, "bdt%d", task);
 
   tc->die    = false;
   tc->name   = strdup (name); /* leaks */
@@ -540,7 +540,7 @@ bdbuf_disk_initialize(void)
     int               fd;
     int               rv;
 
-    snprintf (name, sizeof (name),
+    sniprintf (name, sizeof (name),
               BDBUF_DISK_DEVICE_BASE_NAME "%" PRIu32, minor);
 
     bdd->name = strdup (name);
diff --git a/testsuites/psxtests/psxfile01/test.c b/testsuites/psxtests/psxfile01/test.c
index 4f53c1d..f7bdda4 100644
--- a/testsuites/psxtests/psxfile01/test.c
+++ b/testsuites/psxtests/psxfile01/test.c
@@ -565,7 +565,7 @@ since new path is not valid");
 
   puts( "fprintf to /tmp/j" );
   for (i=1 ; i<=5 ; i++) {
-    status = fprintf( file, "This is call %d to fprintf\n", i );
+    status = fiprintf( file, "This is call %d to fprintf\n", i );
     rtems_test_assert( status );
     printf( "(%d) %d characters written to the file\n", i, status );
   }
diff --git a/testsuites/psxtests/psximfs02/init.c b/testsuites/psxtests/psximfs02/init.c
index e5f51ce..7708045 100644
--- a/testsuites/psxtests/psximfs02/init.c
+++ b/testsuites/psxtests/psximfs02/init.c
@@ -70,9 +70,9 @@ rtems_task Init(
   rtems_test_assert( status == 0 );
 
   for( i = 1 ; ; ++i ) {
-    sprintf( linkname_p, "dir01-link%04d", i-1 );
-    sprintf( linkname_n, "dir01-link%04d", i );
-    printf( "\nCreating link %s for %s\n", linkname_n, linkname_p );
+    siprintf( linkname_p, "dir01-link%04d", i-1 );
+    siprintf( linkname_n, "dir01-link%04d", i );
+    iprintf( "\nCreating link %s for %s\n", linkname_n, linkname_p );
     status = link( linkname_p, linkname_n );
     if( status != 0 ) {
       puts("Link creation failed" );
diff --git a/testsuites/psxtests/psxpasswd02/init.c b/testsuites/psxtests/psxpasswd02/init.c
index 0bec2e2..c1ba1d8 100644
--- a/testsuites/psxtests/psxpasswd02/init.c
+++ b/testsuites/psxtests/psxpasswd02/init.c
@@ -90,7 +90,7 @@ rtems_task Init(
 
   fp = fopen( "/etc/passwd", "w" );
   rtems_test_assert( fp != NULL );
-  fprintf( fp, "bharath:x:-1:-a:Dummy::/:/bin/bash\n" );
+  fiprintf( fp, "bharath:x:-1:-a:Dummy::/:/bin/bash\n" );
   fclose( fp );
 
   puts( "Init - Creating /etc/group" );
@@ -99,7 +99,7 @@ rtems_task Init(
 
   fp = fopen( "/etc/group", "w" );
   rtems_test_assert( fp != NULL );
-  fprintf( fp, "admin::1:root,su,super-user\n" );
+  fiprintf( fp, "admin::1:root,su,super-user\n" );
   fclose( fp );
 
   puts( "Init - setpwent() -- OK" );
@@ -121,7 +121,7 @@ rtems_task Init(
 
   fp = fopen( "/etc/passwd", "w" );
   rtems_test_assert( fp != NULL );
-  fprintf( fp, "rtems:x:1:1:dummy::/:/bin/bash:" );
+  fiprintf( fp, "rtems:x:1:1:dummy::/:/bin/bash:" );
   fclose( fp );
 
   puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
@@ -131,7 +131,7 @@ rtems_task Init(
 
   fp = fopen( "/etc/passwd", "w" );
   rtems_test_assert( fp != NULL );
-  fprintf( fp, "user\n:x:2:2:dummy::/:/bin/sh\n" );
+  fiprintf( fp, "user\n:x:2:2:dummy::/:/bin/sh\n" );
   fclose( fp );
 
   puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
@@ -141,7 +141,7 @@ rtems_task Init(
 
   fp = fopen( "/etc/passwd", "w" );
   rtems_test_assert( fp != NULL );
-  fprintf( fp, "user:x:999999999999:1:dummy::/:/bin/sh\n" );
+  fiprintf( fp, "user:x:999999999999:1:dummy::/:/bin/sh\n" );
   fclose( fp );
 
   puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
@@ -149,11 +149,11 @@ rtems_task Init(
   rtems_test_assert( !pw ); 
   rtems_test_assert( errno == EINVAL );
 
-  sprintf( str, "user:x:%d%d:1:dummy::/:/bin/sh\n", max_int/10, max_int%10+1 );
+  siprintf( str, "user:x:%d%d:1:dummy::/:/bin/sh\n", max_int/10, max_int%10+1 );
 
   fp = fopen( "/etc/passwd", "w" );
   rtems_test_assert( fp != NULL );
-  fprintf( fp, str );
+  fiprintf( fp, str );
   fclose( fp );
 
   puts( "Init - getpwnam(\"root\") -- expected EINVAL" );
@@ -163,7 +163,7 @@ rtems_task Init(
 
   fp = fopen( "/etc/passwd", "w" );
   rtems_test_assert( fp != NULL );
-  fprintf( fp, "\
+  fiprintf( fp, "\
     ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\
     ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\
     ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\
diff --git a/testsuites/psxtests/psxstat/test.c b/testsuites/psxtests/psxstat/test.c
index 09ebb96..5d7d231 100644
--- a/testsuites/psxtests/psxstat/test.c
+++ b/testsuites/psxtests/psxstat/test.c
@@ -423,7 +423,7 @@ void make_too_many_links(void)
 
   for (i=1; i<= LINK_MAX; i++) {
 
-    sprintf(name,"/LinkName%d",i);
+    siprintf(name,"/LinkName%d",i);
     printf( "Making file %s\n", name );
     status = link("/dummy" , name );
     if( i < LINK_MAX )
@@ -517,14 +517,14 @@ void make_many_symlinks(
 
   link_file = real_file;
   for (i=1; i < link_count; i++) {
-    sprintf( name1, "%04d", i );
+    siprintf( name1, "%04d", i );
     make_a_symlink( link_file, name1 );
     strcpy( name2, name1 );
     link_file = name2;
   }
 
   for (i=1; i < link_count; i++) {
-    sprintf( name1, "%04d", i );
+    siprintf( name1, "%04d", i );
     stat_a_file( name1 );
     lstat_a_file( name1 );
   }
diff --git a/testsuites/smptests/smp03/tasks.c b/testsuites/smptests/smp03/tasks.c
index 8d5ac4a..e94ee26 100644
--- a/testsuites/smptests/smp03/tasks.c
+++ b/testsuites/smptests/smp03/tasks.c
@@ -20,7 +20,7 @@ rtems_task Test_task(
   char              task_name[5];
 
   /* Show that this task is running on cpu X */
-  sprintf( task_name, "TA%" PRIuPTR, task_index );
+  siprintf( task_name, "TA%" PRIuPTR, task_index );
   PrintTaskInfo( task_name );
 
   TaskRan[task_index] = true;
diff --git a/testsuites/smptests/smp08/init.c b/testsuites/smptests/smp08/init.c
index f167fb2..301b6f1 100644
--- a/testsuites/smptests/smp08/init.c
+++ b/testsuites/smptests/smp08/init.c
@@ -78,7 +78,7 @@ rtems_task Init(
 
   for ( i=1; i <= rtems_get_processor_count() *3; i++ ) {
 
-    sprintf(ch, "%02" PRIu32, i );
+    siprintf(ch, "%02" PRIu32, i );
     status = rtems_task_create(
       rtems_build_name( 'T', 'A', ch[0], ch[1] ),
       2,
diff --git a/testsuites/smptests/smpaffinity01/init.c b/testsuites/smptests/smpaffinity01/init.c
index 4c052ae..a56043f 100644
--- a/testsuites/smptests/smpaffinity01/init.c
+++ b/testsuites/smptests/smpaffinity01/init.c
@@ -117,7 +117,7 @@ void Validate_affinity(void )
   /* Fill the remaining cpus with med priority tasks */
   puts( "Init - Create Medium priority tasks");
   for (i=0; i<(cpu_count-1); i++){
-    sprintf(ch, "%01" PRId32, i+1 );
+    siprintf(ch, "%01" PRId32, i+1 );
     sc = rtems_task_create(
       rtems_build_name( 'C', 'P', 'U', ch[0] ),
       2,
@@ -145,7 +145,7 @@ void Validate_affinity(void )
     CPU_ZERO(&cpuset1);
     CPU_SET(i, &cpuset1);
 
-    sprintf(ch, "%01" PRId32, (uint32_t) 0 );
+    siprintf(ch, "%01" PRId32, (uint32_t) 0 );
     sc = rtems_task_create(
       rtems_build_name( 'X', 'T', 'R', ch[0] ),
       10,
-- 
2.7.4



More information about the devel mailing list