cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Any explanation behind the value of CURLAUTH_ONLY?

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Tue, 13 Jan 2015 22:57:41 +0100

On Tue, Jan 13, 2015 at 11:49:44AM -0200, Jonathan C. wrote:
> Currently it's 1 << 31 (2147483648), which is greater than the biggest 32 bit signed int. I'm asking that because javascript will cast all of its double values into signed 32-bit integers to do the bitwise operation, causing given value to overflow to -2147483648.
>
> However, in the node.js binding I'm working on, it seems to work even with the overflow, for example:
>
> Setting HTTPAUTH to DIGEST | ONLY, which value is going to be -2147483644, works as expected, it tries to authenticate using only DIGEST.
>
> So, can someone explain what is going on to me?

A machine using twos-complement arithmetic will represent the 32-bit signed
value -2147483648 and the 32 bit unsigned value 1<<31 (a.k.a. 2147483648) with
the same pattern of bits in memory. The interpretation of these bits as a
signed or unsigned number will differ, but since libcurl treats the result as a
raw set of bits, it doesn't really matter. This treatment encourages sloppy
and nonportable programming practises but in this case it works out in the end.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-01-13