elinks
elinks copied to clipboard
small gcc-14 incompatibility
hi
I got this compile time error while building latest master with just released gcc-14.1.0 on a 64 bit machine:
gcc -m64 -Isrc/elinks.p -Isrc -I../src -I. -I.. -I/opt/stow.d/versions/openssl-3.3.0/usr/include -I/opt/stow.d/versions/libidn2-2.3.7/usr/include -I/opt/stow.d/versions/sqlite-3.46.0/usr/include -I/opt/stow.d/versions/expat-2.6.2/usr/include -I/opt/stow.d/versions/python3-3.12.3/usr/python3/include/python3.12 -I/opt/stow.d/stow/quickjs-4felinks/usr/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g '-DGETTEXT_PACKAGE="elinks"' '-DBUILD_ID=""' -DHAVE_CONFIG_H -fno-strict-aliasing -Wno-address -Wno-builtin-declaration-mismatch -MD -MQ src/elinks.p/ecmascript_quickjs_element.c.o -MF src/elinks.p/ecmascript_quickjs_element.c.o.d -o src/elinks.p/ecmascript_quickjs_element.c.o -c ../src/ecmascript/quickjs/element.c
../src/ecmascript/quickjs/element.c: In function ‘js_element_get_property_checked’:
../src/ecmascript/quickjs/element.c:109:17: warning: unused variable ‘r’ [-Wunused-variable]
109 | JSValue r;
| ^
../src/ecmascript/quickjs/element.c: In function ‘js_element_set_property_checked’:
../src/ecmascript/quickjs/element.c:170:17: warning: unused variable ‘r’ [-Wunused-variable]
170 | JSValue r;
| ^
../src/ecmascript/quickjs/element.c: In function ‘js_element_set_property_value’:
../src/ecmascript/quickjs/element.c:2058:17: warning: unused variable ‘r’ [-Wunused-variable]
2058 | JSValue r;
| ^
../src/ecmascript/quickjs/element.c: In function ‘js_element_matches’:
../src/ecmascript/quickjs/element.c:2950:32: error: passing argument 2 of ‘JS_NewBool’ makes integer from pointer without a cast [-Wint-conversion]
2950 | return JS_NewBool(ctx, res);
| ^~~
| |
| void *
In file included from ../src/ecmascript/ecmascript.h:19,
from ../src/ecmascript/quickjs/element.c:25:
/opt/stow.d/stow/quickjs-4felinks/usr/include/quickjs/quickjs.h:505:67: note: expected ‘int’ but argument is of type ‘void *’
505 | static js_force_inline JSValue JS_NewBool(JSContext *ctx, JS_BOOL val)
| ^
It turns out that the error is generated specifically by the latest version of gcc: gcc-13.2.0 emits only a warning.
This fixes the compilation error:
diff -c src/ecmascript/quickjs/element.c.CAST_TO_INT src/ecmascript/quickjs/element.c
*** src/ecmascript/quickjs/element.c.CAST_TO_INT 2024-05-10 13:45:14.882834031 +0200
--- src/ecmascript/quickjs/element.c 2024-05-10 13:45:14.882834031 +0200
***************
*** 2947,2953 ****
void *res = el_match_selector(selector, el);
JS_FreeCString(ctx, selector);
! return JS_NewBool(ctx, res);
}
static JSValue
--- 2947,2953 ----
void *res = el_match_selector(selector, el);
JS_FreeCString(ctx, selector);
! return JS_NewBool(ctx,(int)(uintptr_t)res);
}
static JSValue
(the double cast is just to prevent a further warning about casting a pointer to an integer of different size)
Not a big deal, but since the patch makes the right thing and shoud be fully compatible with any compiler, compiler version and 32/64 bit arch, you might consider to apply it
thanks a lot for your valuable work
ciao -gabriele
Thanks, I modfied code to check if is not NULL. More readable imo.