From 3cfd4acd149e883a96c8250383ea1df1c4a4044e Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Sun, 9 Aug 2015 20:27:10 +0100 Subject: [PATCH] Use ptrdiff_t instead of uint32_t to represent offset in buffer. Found with [-Wconversion]. --- re2c/src/parse/scanner.cc | 10 +++++----- re2c/src/parse/scanner.h | 6 +++--- re2c/src/util/substr.h | 7 +++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/re2c/src/parse/scanner.cc b/re2c/src/parse/scanner.cc index f4efa780..1f2774b1 100644 --- a/re2c/src/parse/scanner.cc +++ b/re2c/src/parse/scanner.cc @@ -182,7 +182,7 @@ void Scanner::config(const std::string & cfg, const std::string & val) std::string strVal; - const uint32_t val_len = val.size (); + const size_t val_len = val.size (); if (val_len >= 2 && val[0] == val[val_len - 1] && (val[0] == '"' || val[0] == '\'')) { @@ -325,7 +325,7 @@ char *Scanner::fill(char *cursor, uint32_t need) { if(!eof) { - uint32_t cnt; + ptrdiff_t cnt; /* Do not get rid of anything when rFlag is active. Otherwise * get rid of everything that was already handedout. */ if (!rFlag) @@ -384,7 +384,7 @@ void Scanner::set_in_parse(bool new_in_parse) in_parse = new_in_parse; } -void Scanner::fatal_at(uint32_t line, uint32_t ofs, const char *msg) const +void Scanner::fatal_at(uint32_t line, ptrdiff_t ofs, const char *msg) const { std::cerr << "re2c: error: " << "line " << line << ", column " << (tchar + ofs + 1) << ": " @@ -392,7 +392,7 @@ void Scanner::fatal_at(uint32_t line, uint32_t ofs, const char *msg) const exit(1); } -void Scanner::fatal(uint32_t ofs, const char *msg) const +void Scanner::fatal(ptrdiff_t ofs, const char *msg) const { fatal_at(in_parse ? tline : cline, ofs, msg); } @@ -446,7 +446,7 @@ void Scanner::reuse() void Scanner::restore_state(const ScannerState& state) { - int diff = bot - state.bot; + ptrdiff_t diff = bot - state.bot; char *old_bot = bot; char *old_lim = lim; char *old_top = top; diff --git a/re2c/src/parse/scanner.h b/re2c/src/parse/scanner.h index 3eda866f..2138fc55 100644 --- a/re2c/src/parse/scanner.h +++ b/re2c/src/parse/scanner.h @@ -38,7 +38,7 @@ struct ScannerState char * top; char * eof; - uint32_t tchar; + ptrdiff_t tchar; uint32_t tline; uint32_t cline; @@ -83,11 +83,11 @@ public: uint32_t get_line() const; const std::string & get_fname () const; void set_in_parse(bool new_in_parse); - void fatal_at(uint32_t line, uint32_t ofs, const char *msg) const; + void fatal_at(uint32_t line, ptrdiff_t ofs, const char *msg) const; void fatalf_at(uint32_t line, const char*, ...) const RE2C_GXX_ATTRIBUTE ((format (printf, 3, 4))); void fatalf(const char*, ...) const RE2C_GXX_ATTRIBUTE ((format (printf, 2, 3))); void fatal(const char*) const; - void fatal(uint32_t, const char*) const; + void fatal(ptrdiff_t, const char*) const; void config(const std::string &, int); void config(const std::string &, const std::string &); diff --git a/re2c/src/util/substr.h b/re2c/src/util/substr.h index 79072850..a78c704e 100644 --- a/re2c/src/util/substr.h +++ b/re2c/src/util/substr.h @@ -1,7 +1,6 @@ #ifndef _RE2C_UTIL_SUBSTR_ #define _RE2C_UTIL_SUBSTR_ -#include "src/util/c99_stdint.h" #include "src/util/forbid_copy.h" namespace re2c @@ -12,14 +11,14 @@ class SubStr public: const char * str; const char * const org; - uint32_t len; + size_t len; - inline SubStr (const char * s, uint32_t l) + inline SubStr (const char * s, size_t l) : str (s) , org (s) , len (l) {} - inline uint32_t ofs () const + inline ptrdiff_t ofs () const { return str - org; } -- 2.40.0