cynthia / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

EnvToInt64(envname, dflt) Function didn't work correctly if dflt is bigger than "1<<30" #377

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.envname didn't exist
2.dflt is bigger than 1<<30 such as 2<<31
3.EnvToInt64 return wrong result

What is the expected output? What do you see instead?
expect output: 4294967296
instead I see: 0

What version of the product are you using? On what operating system?
1.8.1

Please provide any additional information below.

Original issue reported on code.google.com by huangjia...@gmail.com on 4 Nov 2011 at 5:12

GoogleCodeExporter commented 9 years ago
Sorry not bigger than 1<<30, 
bigger than 1<<32-1

Original comment by huangjia...@gmail.com on 4 Nov 2011 at 5:14

GoogleCodeExporter commented 9 years ago
Some quick testing on my end shows that you need to be explicit with the values 
you are passing in to the macro. For example:

    EnvToInt64("some_env_var", 1ULL << 32)

Which correctly yields 4294967296. In your case the value being shifted is 
implicitly being treated as a 32-bit integer.

Original comment by chapp...@gmail.com on 4 Nov 2011 at 5:58

GoogleCodeExporter commented 9 years ago
Does this address your concern? I couldn't find a use of EnvToInt64 in 1.8.3 
that suffered from this issue.

Original comment by chapp...@gmail.com on 4 Nov 2011 at 3:15

GoogleCodeExporter commented 9 years ago
Comment #2 is right on here -- the problem is with '2<<31', which is not valid 
C on  systems where int is 32 bits.  You need to cast the '2' to a type that is 
wide enough to be shifted that much.

Original comment by csilv...@gmail.com on 4 Nov 2011 at 7:23