{"id": 1544, "title": "Ticket #1544: Classad printing problem with INT_MIN valued attribute", "description": "<blockquote>\nOn my 64 bit machine, if I set a value to INT_MIN, condor_status -l display it oddly.  condor_status -format \"%d\" seems to be ok, though:\n\n<p></p><div class=\"code\">\n<pre class=\"code\">$ grep GGT ResAttributes.cpp\n                cp-&gt;Assign( \"GGT\", INT_MIN);\nbash-3.2$ condor_status -l | grep GGT\nGGT =  - --2147483648\n</pre></div>\n\n\n<p>On a 32-bit machine, the value is -2147483647 (without the extra minus signs).\n\n</p><p>The problem is that the new <span class=\"wiki\"><a class=\"missing\" href=\"wiki?p=ClassAds\" title=\"Class Ads\">ClassAds</a></span> parser parses -1 as '-' '1'. That is, the unary minus operator followed by the integer 1. This works ok for most integer and real values, as when the expression is evaluated, the correct value is reconstructed. INT_MIN (aka -2147483648) is an exception, since the negated value (2147483648) can't be represented in signed 32-bits. The parser calls strtol() on the string representing the number (without the minus), then casts the result to an int. On a 32-bit machine, strtol() detects overflow and returns LONG_MAX (which is the same as INT_MAX, 2147483647). On a 64-bit machine, 2147483648 is returned in 64 bits, which is then truncated to 32 bits by the cast, resulting in the value -2147483648. When this is unparsed, an extra minus sign ends up in front (for the unary minus operator). If the resulting string is parsed and unparsed again, another minus sign appears.\n\n</p><p>The parsing code needs to be modified to treat -1 as a negative number, not the negation of a positive number. It also must take extra care with values returned by strtol() on 64-bit platforms, reducing large values to INT_MIN and INT_MAX, rather than truncating to 32 bits. The compat <span class=\"wiki\"><a class=\"missing\" href=\"wiki?p=ClassAd\" title=\"Class Ad\">ClassAd</a></span> layer provides methods to insert unsigned and long values into an ad, which just cast the values to int. We should consider removing these.</p></blockquote>", "remarks": "<blockquote>\n<em>2010-Aug-02 11:09:16 by jfrey:</em> <br/>\n\nPushed fixes to master for 7.5.4.</blockquote>", "derived_tickets": "", "attachments": "<html><head></head><body></body></html>", "check_ins": "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tbody><tr><td align=\"right\" valign=\"top\" width=\"160\">2010-Aug-02 11:00</td>\n<td align=\"center\" valign=\"top\" width=\"30\">\n<span class=\"icon dot\">\u00a0</span></td>\n<td align=\"left\" valign=\"top\"> \nCheck-in <span class=\"chng\"><a href=\"https://github.com/htcondor/htcondor/commit/0f294ba857050759cd41b3370127d0ddebdf56f6\">[18685]</a></span>: Improve handling of large integers when parsing a new <span class=\"wiki\"><a class=\"missing\" href=\"wiki?p=ClassAd\" title=\"Class Ad\">ClassAd</a></span> <span class=\"ticket\"><a class=\"resolved\" href=\"/wiki-archive/tickets/?ticket=1544\" onclick=\"get_ticket_and_populate_wrapper('1544'); return false;\" title=\"Classad printing problem with INT_MIN valued attribute\">#1544</a></span> The parser uses strtol() to convert integers from ASCII text to a 32-bit representation. On a 64-bit machine, strtol() returns a 64-bit value, which the parser truncates to 32 bits. If the value doesn't fit in 32 bits, the parser should\u00a0[...]\n (By <NAME> )</td></tr>\n<tr><td align=\"right\" valign=\"top\" width=\"160\">2010-Aug-02 10:54</td>\n<td align=\"center\" valign=\"top\" width=\"30\">\n<span class=\"icon dot\">\u00a0</span></td>\n<td align=\"left\" valign=\"top\"> \nCheck-in <span class=\"chng\"><a href=\"https://github.com/htcondor/htcondor/commit/567cc9b8d8c22dc068901af48e015abd27025552\">[18684]</a></span>: Fix parsing of negative nubmers on new <span class=\"wiki\"><a class=\"missing\" href=\"wiki?p=ClassAds\" title=\"Class Ads\">ClassAds</a></span> <span class=\"ticket\"><a class=\"resolved\" href=\"/wiki-archive/tickets/?ticket=1544\" onclick=\"get_ticket_and_populate_wrapper('1544'); return false;\" title=\"Classad printing problem with INT_MIN valued attribute\">#1544</a></span> The new <span class=\"wiki\"><a class=\"missing\" href=\"wiki?p=ClassAds\" title=\"Class Ads\">ClassAds</a></span> parser parses -1 as '-' '1'. That is, the unary minus operator followed by the integer 1. This works ok for most integer and real values, as when the expression is evaluated, the correct value is reconstructed. INT_MIN (aka -2147483648)\u00a0[...]\n (By <NAME> )</td></tr>\n</tbody></table>", "type": "defect", "last_change": "2010-Aug-19 09:26", "status": "resolved", "created": "2010-Jul-29 10:41", "fixed_version": "2010-Jul-29 10:41", "broken_version": "v070502", "priority": "2", "subsystem": "Daemons", "assigned_to": "jfrey", "derived_from": "", "creator": "gthain", "rust": "", "customer_group": "other", "visibility": "public", "notify": "", "due_date": ""}