]> granicus.if.org Git - re2c/commitdiff
Some more explicit casts in lexer fill procedure (found with [-Wsign-conversion]).
authorUlya Trofimovich <skvadrik@gmail.com>
Fri, 14 Aug 2015 13:29:19 +0000 (14:29 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Fri, 14 Aug 2015 13:36:09 +0000 (14:36 +0100)
Lexer tries to maintain certain layout of pointers to buffer.
Buffer refilling procedure relies on that layout.

re2c/src/parse/scanner.cc

index b7c9e823bee63c8f95322e8e055ccbf391893932..7073db731c26de8dffee78497cefa82d966a6f74 100644 (file)
@@ -332,7 +332,8 @@ void Scanner::fill (uint32_t need)
                        const ptrdiff_t diff = tok - bot;
                        if (diff > 0)
                        {
-                               memmove(bot, tok, top - tok);
+                               const size_t move = static_cast<size_t> (top - tok);
+                               memmove (bot, tok, move);
                                tok -= diff;
                                ptr -= diff;
                                cur -= diff;
@@ -348,12 +349,13 @@ void Scanner::fill (uint32_t need)
                }
                if (top - lim < need)
                {
-                       char *buf = new char[(lim - bot) + need];
+                       const size_t copy = static_cast<size_t> (lim - bot);
+                       char * buf = new char[copy + need];
                        if (!buf)
                        {
                                fatal("Out of memory");
                        }
-                       memcpy(buf, bot, lim - bot);
+                       memcpy (buf, bot, copy);
                        tok = &buf[tok - bot];
                        ptr = &buf[ptr - bot];
                        cur = &buf[cur - bot];