diff mbox

[v2,for-4.7,13/14] oxenstored: fix error when shifting negative value

Message ID 1461682343-20597-14-git-send-email-roger.pau@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roger Pau Monné April 26, 2016, 2:52 p.m. UTC
By explicitly casting it to unsigned.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
---
 tools/ocaml/xenstored/systemd_stubs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Wei Liu April 26, 2016, 3:35 p.m. UTC | #1
The title is a bit too cryptic to me. Where do that shift happen?

Wei.
Andrew Cooper April 26, 2016, 3:37 p.m. UTC | #2
On 26/04/16 16:35, Wei Liu wrote:
> The title is a bit too cryptic to me. Where do that shift happen?

Ocaml stores integers shifted left by one, and with the bottom bit set.

Values with the bottom bit clear are pointers into the GC'd heap. 
Values with the bottom bit set are integers, and need to be shifted by 1
bit to have calculations performed.

Underlying patch Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper April 26, 2016, 3:43 p.m. UTC | #3
On 26/04/16 16:43, Wei Liu wrote:
> On Tue, Apr 26, 2016 at 04:37:49PM +0100, Andrew Cooper wrote:
>> On 26/04/16 16:35, Wei Liu wrote:
>>> The title is a bit too cryptic to me. Where do that shift happen?
>> Ocaml stores integers shifted left by one, and with the bottom bit set.
>>
>> Values with the bottom bit clear are pointers into the GC'd heap. 
>> Values with the bottom bit set are integers, and need to be shifted by 1
>> bit to have calculations performed.
>>
> This is better.
>
> Roger, can you add the above paragraphs to commit message? Thanks.

P.S. this is why Ocaml integers are 31 or 63 bits wide, and cause all
kinds of "fun" issues when interfacing with C which makes use of all
bits available in an integer.

~Andrew
Wei Liu April 26, 2016, 3:43 p.m. UTC | #4
On Tue, Apr 26, 2016 at 04:37:49PM +0100, Andrew Cooper wrote:
> On 26/04/16 16:35, Wei Liu wrote:
> > The title is a bit too cryptic to me. Where do that shift happen?
> 
> Ocaml stores integers shifted left by one, and with the bottom bit set.
> 
> Values with the bottom bit clear are pointers into the GC'd heap. 
> Values with the bottom bit set are integers, and need to be shifted by 1
> bit to have calculations performed.
> 

This is better.

Roger, can you add the above paragraphs to commit message? Thanks.

Wei.
diff mbox

Patch

diff --git a/tools/ocaml/xenstored/systemd_stubs.c b/tools/ocaml/xenstored/systemd_stubs.c
index 1bd5dea..a78a72b 100644
--- a/tools/ocaml/xenstored/systemd_stubs.c
+++ b/tools/ocaml/xenstored/systemd_stubs.c
@@ -124,7 +124,7 @@  CAMLprim value ocaml_sd_listen_fds(value connect_to)
 	CAMLparam1(connect_to);
 	CAMLlocal1(sock_ret);
 
-	sock_ret = Val_int(-1);
+	sock_ret = Val_int(-1U);
 
 	CAMLreturn(sock_ret);
 }
@@ -144,7 +144,7 @@  CAMLprim value ocaml_sd_notify_ready(value ignore)
 	CAMLparam1(ignore);
 	CAMLlocal1(ret);
 
-	ret = Val_int(-1);
+	ret = Val_int(-1U);
 
 	CAMLreturn(ret);
 }