[PPL-devel] [GIT] ppl/ppl(master): Avoid implicit conversions changing type signedness.

Enea Zaffanella zaffanella at cs.unipr.it
Fri Feb 24 10:14:27 CET 2012


Module: ppl/ppl
Branch: master
Commit: 6b48ffdf47e595250802fe87464fe348bc488d45
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=6b48ffdf47e595250802fe87464fe348bc488d45

Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date:   Fri Feb 24 10:13:34 2012 +0100

Avoid implicit conversions changing type signedness.
Detected by ECLAIR service utypflag.

---

 src/c_streambuf.cc      |   14 ++++++++++----
 src/c_streambuf.defs.hh |    1 +
 src/stdiobuf.cc         |   12 +++++++++---
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/c_streambuf.cc b/src/c_streambuf.cc
index 83ecf0f..c76ca44 100644
--- a/src/c_streambuf.cc
+++ b/src/c_streambuf.cc
@@ -23,6 +23,8 @@ site: http://bugseng.com/products/ppl/ . */
 
 #include "ppl-config.h"
 #include "c_streambuf.defs.hh"
+#include "globals.defs.hh"
+#include "assert.hh"
 
 namespace Parma_Polyhedra_Library {
 
@@ -48,22 +50,24 @@ c_streambuf::underflow() {
 
 std::streamsize
 c_streambuf::xsgetn(char_type* s, std::streamsize n) {
+  PPL_ASSERT(n >= 0);
   if (n == 0)
     return n;
   const int_type eof = traits_type::eof();
-  int a;
+  const size_t sz_n = static_cast<size_t>(n);
+  size_t a;
   if (traits_type::eq_int_type(next_char_buf, eof))
     a = 0;
   else {
     s[0] = static_cast<char_type>(next_char_buf);
     a = 1;
   }
-  std::streamsize r = cb_read(s + a, n - a) + a;
+  const size_t r = cb_read(s + a, sz_n - a) + a;
   if (r > 0)
     unget_char_buf = traits_type::to_int_type(s[r - 1]);
   else
     unget_char_buf = traits_type::eof();
-  return r;
+  return static_cast<std::streamsize>(r);
 }
 
 c_streambuf::int_type
@@ -76,7 +80,9 @@ c_streambuf::pbackfail(int_type c) {
 
 std::streamsize
 c_streambuf::xsputn(const char_type* s, std::streamsize n) {
-  return cb_write(s, n);
+  PPL_ASSERT(n >= 0);
+  size_t r = cb_write(s, static_cast<size_t>(n));
+  return static_cast<std::streamsize>(r);
 }
 
 c_streambuf::int_type
diff --git a/src/c_streambuf.defs.hh b/src/c_streambuf.defs.hh
index b8e0d98..2a349af 100644
--- a/src/c_streambuf.defs.hh
+++ b/src/c_streambuf.defs.hh
@@ -26,6 +26,7 @@ site: http://bugseng.com/products/ppl/ . */
 
 #include "c_streambuf.types.hh"
 #include <streambuf>
+#include <cstddef>
 
 class Parma_Polyhedra_Library::c_streambuf
   : public std::basic_streambuf<char, std::char_traits<char> > {
diff --git a/src/stdiobuf.cc b/src/stdiobuf.cc
index 529f1bf..8a5fe95 100644
--- a/src/stdiobuf.cc
+++ b/src/stdiobuf.cc
@@ -23,6 +23,9 @@ site: http://bugseng.com/products/ppl/ . */
 
 #include "ppl-config.h"
 #include "stdiobuf.defs.hh"
+#include "globals.defs.hh"
+#include "assert.hh"
+#include <cstddef>
 
 namespace Parma_Polyhedra_Library {
 
@@ -40,12 +43,13 @@ stdiobuf::underflow() {
 
 std::streamsize
 stdiobuf::xsgetn(char_type* s, std::streamsize n) {
-  std::streamsize r = fread(s, 1, n, fp);
+  PPL_ASSERT(n >= 0);
+  size_t r = fread(s, 1, static_cast<size_t>(n), fp);
   if (r > 0)
     unget_char_buf = traits_type::to_int_type(s[r - 1]);
   else
     unget_char_buf = traits_type::eof();
-  return r;
+  return static_cast<std::streamsize>(r);
 }
 
 stdiobuf::int_type
@@ -58,7 +62,9 @@ stdiobuf::pbackfail(int_type c) {
 
 std::streamsize
 stdiobuf::xsputn(const char_type* s, std::streamsize n) {
-  return fwrite(s, 1, n, fp);
+  PPL_ASSERT(n >= 0);
+  size_t r = fwrite(s, 1, static_cast<size_t>(n), fp);
+  return static_cast<std::streamsize>(r);
 }
 
 stdiobuf::int_type




More information about the PPL-devel mailing list