Skip to content

vector: don't use an `int` as pointer

As explained in https://docs.gtk.org/glib/conversion-macros.html#type-conversion:

Warning: You may not store pointers in integers. This is not portable in any way, shape or form. These macros only allow storing integers in pointers, and only preserve 32 bits of the integer; values outside the range of a 32-bit integer will be mangled.

Indeed, this was causing the vector-index test to fail on Chimera Linux x86_64, as shown in this LLDB backtrace:

* thread #1, name = 'vector-index', stop reason = signal SIGSEGV: address not mapped to object (fault address: 0x7fff00000030)
  * frame #0: 0x00007fffef453746 libglib-2.0.so.0`g_hash_table_iter_next(iter=0x00007fffffffe000, key=0x00007fffffffdffc, value=0x00007fffffffdff0) at ghash.c:1145:63
    frame #1: 0x00007ffff7fd78aa libshumate-1.0.so.1`shumate_vector_render_scope_index_layer(self=0x00007fffffffe0b8) at shumate-vector-render-scope.c:486:14
    frame #2: 0x000055555555b9a1 vector-index`compute_bitset(reader=0x00007fffede00520, json=<unavailable>, layer=<unavailable>, index_description_out=0x0000000000000000) at vector-index.c:109:3
    frame #3: 0x000055555555b461 vector-index`test_vector_index_eval at vector-index.c:166:12
    frame #4: 0x00007fffef4b0ee0 libglib-2.0.so.0`g_test_run_suite_internal [inlined] test_case_run(tc=0x00007fffedc00750, test_run_name="/vector-index/eval", path=0x0000000000000000) at gtestutils.c:2988:15
    frame #5: 0x00007fffef4b067f libglib-2.0.so.0`g_test_run_suite_internal(suite=0x00007fffede00a30, path=0x0000000000000000) at gtestutils.c:3090:12
    frame #6: 0x00007fffef4b11bb libglib-2.0.so.0`g_test_run_suite_internal(suite=0x00007fffede010c0, path=0x0000000000000000) at gtestutils.c:0:3
    frame #7: 0x00007fffef4aed12 libglib-2.0.so.0`g_test_run_suite(suite=0x00007fffede010c0) at gtestutils.c:3189:13
    frame #8: 0x00007fffef4ae9fa libglib-2.0.so.0`g_test_run at gtestutils.c:2275:7
    frame #9: 0x000055555555a8c9 vector-index`main(argc=1, argv=0x00007fffffffe4c8) at vector-index.c:192:10
    frame #10: 0x00007fffefa57c2a libc.so`libc_start_main_stage2(main=(vector-index`main at vector-index.c:185), argc=<unavailable>, argv=0x00007fffffffe4c8) at __libc_start_main.c:95:7
    frame #11: 0x000055555555a736 vector-index`_start + 22

Instead, use an actual gpointer and convert to to an integer as needed.

Edited by triallax

Merge request reports