Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 May 2016 04:08:45 +0000 (UTC)
From:      "Conrad E. Meyer" <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r299511 - head/lib/libc/tests/stdio
Message-ID:  <201605120408.u4C48jDG044769@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Thu May 12 04:08:45 2016
New Revision: 299511
URL: https://svnweb.freebsd.org/changeset/base/299511

Log:
  print_positional_test: Fix misuse of wchar APIs
  
  These APIs take unit length, not byte length parameters.
  
  Reported by:	Coverity
  CIDs:		1338543, 1338544, 1338545
  Sponsored by:	EMC / Isilon Storage Division

Modified:
  head/lib/libc/tests/stdio/print_positional_test.c

Modified: head/lib/libc/tests/stdio/print_positional_test.c
==============================================================================
--- head/lib/libc/tests/stdio/print_positional_test.c	Thu May 12 03:53:20 2016	(r299510)
+++ head/lib/libc/tests/stdio/print_positional_test.c	Thu May 12 04:08:45 2016	(r299511)
@@ -32,6 +32,7 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <sys/param.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -94,7 +95,7 @@ ATF_TC_WITHOUT_HEAD(positional_wide);
 ATF_TC_BODY(positional_wide, tc)
 {
 
-	swprintf(wbuf1, sizeof wbuf1,
+	swprintf(wbuf1, nitems(wbuf1),
 	    L"|xx %1$s %2$s %3$s %4$s\n"
 	    "|xx %5$s %6$s %7$s %8$s\n"
 	    "|xx %9$s %10$s %11$s %12$s\n"
@@ -117,7 +118,7 @@ ATF_TC_BODY(positional_wide, tc)
 	    "43", "44", 45, -1L, 1LL, -1, 1LL
 	    );
 	temp = correct;
-	mbsrtowcs(wbuf2, &temp, sizeof wbuf2, NULL);
+	mbsrtowcs(wbuf2, &temp, nitems(wbuf2), NULL);
 	ATF_REQUIRE_MSG(wcscmp(wbuf1, wbuf2) == 0,
 	    "buffers didn't match");
 }
@@ -139,7 +140,7 @@ ATF_TC_BODY(positional_precision_wide, t
 	swprintf(wbuf1, sizeof buf, L"%2$.*4$s %2$.*3$s %1$s",
 		 "BSD", "bsd", 2, 1);
 	temp = correct2;
-	mbsrtowcs(wbuf2, &temp, sizeof wbuf2, NULL);
+	mbsrtowcs(wbuf2, &temp, nitems(wbuf2), NULL);
 	ATF_REQUIRE_MSG(wcscmp(wbuf1, wbuf2) == 0,
 	    "buffers didn't match");
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605120408.u4C48jDG044769>