tmerr / i3ipc-rs

A Rust library for controlling i3-wm through its IPC interface
MIT License
106 stars 33 forks source link

Use i64 for container ids #13

Closed soumya92 closed 7 years ago

soumya92 commented 7 years ago

Since container IDs are a C pointer value, on 64-bit operating systems they can overflow i32.

For example, on my current instance:

> i3-msg -t get_tree | jq .| grep '"id"'
"id": 93833137164352,
      "id": 93833137164816,
          "id": 93833137167344,
              "id": 93833137167840,
      "id": 93833137176192,
          "id": 93833137176768,
              "id": 93833137384176,
          "id": 93833137180048,
              "id": 93833137180512,
                  "id": 93833137181104,
          "id": 93833137189616,
      "id": 93833137195472,
          "id": 93833137195968,
              "id": 93833137410608,
          "id": 93833137199264,
              "id": 93833137199728,
                  "id": 93833137200320,
              "id": 93833137206256,
                  "id": 93833137206816,
                      "id": 93833137207280,
              "id": 93833137215824,
                  "id": 93833137216384,
                      "id": 93833137216848,
                      "id": 93833137220176,
                      "id": 93833137223504,
                      "id": 93833137444240,
                      "id": 93833137226736,
          "id": 93833137237936,
tmerr commented 7 years ago

Nice catch.

The code in i3/src/ipc.c dumps an unsigned pointer which is passed through this helper macro that translates to yajl_gen_integer which casts it to a long long int that is turned into json via the %lld C format string. Long story short... even if you were using all 64-bits of your address space, it would be signed in the json, so i64 is definitely the way to go.

Mergity merged