ominux / vtr-verilog-to-routing

Automatically exported from code.google.com/p/vtr-verilog-to-routing
0 stars 0 forks source link

ODIN constant string to long error #34

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following code from odin_util.c:192 contains a problem:
    #ifdef LLONG_MAX
    long long number = strtoll(orig_string, NULL, 10);
    if (number == LLONG_MAX || number == LLONG_MIN)
        error_message(PARSE_ERROR, -1, -1, "This suspected decimal number (%s) is too long for Odin\n", orig_string);
    #else
    long long number = strtol(orig_string, NULL, 10);
    if (number == LONG_MAX || number == LONG_MIN)
        error_message(PARSE_ERROR, -1, -1, "This suspected decimal number (%s) is too long for Odin\n", orig_string);
    #endif

This checks if LLONG_MAX is defined, and if so uses strtoll, otherwise it uses 
strtol.  Unfortunately mcnc.v contains a very large constant (32'd3447127471), 
which is a 32 bit number.  It is too large for a 32-bit signed long, thus 
strtol will error.

In the system I was using, a long long is 8 bytes and a long is 4 bytes; 
however, LLONG_MAX is not defined.  So, the above code uses strtol which 
returns a signed long, and will error with the mentioned constant.  Instead, 
strtoll could be used, even though LLONG_MAX is not defined.  However, without 
LLONG_MAX being defined, you cannot use the same method to check for an error.  
Instead, you need to check the errno.

I propose the above lines be replaced by the following code:
errno = 0;
    long long number = strtoll(orig_string, NULL, 10);
    if (errno == ERANGE) {
        error_message(PARSE_ERROR, -1, -1, "This suspected decimal number (%s) is too long for Odin\n", orig_string);
    }

You need to include <errno.h> as well.

Original issue reported on code.google.com by jeffrey....@gmail.com on 5 Jun 2012 at 6:07

GoogleCodeExporter commented 9 years ago

Original comment by jeffrey....@gmail.com on 5 Jun 2012 at 6:08

GoogleCodeExporter commented 9 years ago
Sorry, I mean mcml.v

Original comment by jeffrey....@gmail.com on 5 Jun 2012 at 6:09

GoogleCodeExporter commented 9 years ago

Original comment by jeffrey....@gmail.com on 7 Jun 2012 at 4:49

GoogleCodeExporter commented 9 years ago
Looks good. 

Original comment by andy16...@gmail.com on 7 Jun 2012 at 4:53