Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build warnings and gcc 14 errors #16

Open
stefan11111 opened this issue Dec 22, 2024 · 0 comments
Open

build warnings and gcc 14 errors #16

stefan11111 opened this issue Dec 22, 2024 · 0 comments

Comments

@stefan11111
Copy link
Contributor

I took a look at the warnings when building tinyx.
There are all the warnings generated by gcc:

devices.c:1184:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
events.c:2424:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]

These are about code formatting.
Maybe you are interested in changing the indentation or putting some braces around if/else statements.

fbbltone.c:429:32: warning: result of '16777215 << 24' requires 49 bits to represent, but 'int' only has 32 bits [-Wshift-overflow=]
fbbltone.c:429:32: warning: result of '16777215 << 24' requires 49 bits to represent, but 'int' only has 32 bits [-Wshift-overflow=]
fbbltone.c:429:32: warning: result of '16777215 << 24' requires 49 bits to represent, but 'int' only has 32 bits [-Wshift-overflow=]
fbbltone.c:429:32: warning: result of '16777215 << 24' requires 49 bits to represent, but 'int' only has 32 bits [-Wshift-overflow=]
fbbltone.c:429:32: warning: result of '16777215 << 16' requires 41 bits to represent, but 'int' only has 32 bits [-Wshift-overflow=]
fbbltone.c:429:32: warning: result of '16777215 << 16' requires 41 bits to represent, but 'int' only has 32 bits [-Wshift-overflow=]
fbbltone.c:429:32: warning: result of '16777215 << 16' requires 41 bits to represent, but 'int' only has 32 bits [-Wshift-overflow=]
fbbltone.c:429:32: warning: result of '16777215 << 16' requires 41 bits to represent, but 'int' only has 32 bits [-Wshift-overflow=]

These are about signed left shift overflow, all generated by one macro.
According to this, the overflow seems intentional: https://gitlab.freedesktop.org/xorg/xserver/-/commit/fd086f87cd1bab53c9e918cb687009e7ac8718d8

However, signed integer overflow is UB, so it should probably be fixed.
One way of fixing it is doing the shift on an unsigned int and casting back to int,
like '((int)(0xffffffU << Mask24Check(x,r)))) : 0)' instead of '0xffffff << Mask24Check(x,r)) : 0)'

shm.c:211:1: warning: type of 'INITARGS' defaults to 'int' [-Wimplicit-int]
xtest.c:83:1: warning: type of 'INITARGS' defaults to 'int' [-Wimplicit-int]
bigreq.c:53:1: warning: type of 'INITARGS' defaults to 'int' [-Wimplicit-int]
xcmisc.c:67:1: warning: type of 'INITARGS' defaults to 'int' [-Wimplicit-int]
sync.c:2299:1: warning: type of 'INITARGS' defaults to 'int' [-Wimplicit-int]
xres.c:376:1: warning: type of 'INITARGS' defaults to 'int' [-Wimplicit-int]
saver.c:242:1: warning: type of 'INITARGS' defaults to 'int' [-Wimplicit-int]
dpms.c:94:1: warning: type of 'INITARGS' defaults to 'int' [-Wimplicit-int]

This is the result of some odd code.
In mi/miinitext.c INITARGS is #defined to be void, and is used for declaring some function prototypes.
However, INITARGS is also used some files under Xext, where it is not defined.
Because it's not defined there, the compiler threats things like foo(INITARGS){...} as K&R functions,
where INITARGS is a variable implicitly defined as int.
This is an error on gcc14 and the fix is either defining INITARGS in each file to void or removing INITARGS from the
code and replacing it with void.
Unless there is some reason for wanting to use INITARGS, I think removing INITARGS and replacing it with void is the better way to fix this.

utils.c:260:10: warning: ignoring return value of 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
kdrive.c:194:17: warning: ignoring return value of 'system' declared with attribute 'warn_unused_result' [-Wunused-result]
linux.c:66:17: warning: ignoring return value of 'chown' declared with attribute 'warn_unused_result' [-Wunused-result]

Some Warnings about unused results. These can be silenced by adding (void)! casts.
This approach was taken in other places in the code, where the casts were only (void) casts, because older compilers silenced that warning with only a (void) cast.

kmode.c:250:18: warning: 'kdNumMonitorTimings' defined but not used [-Wunused-const-variable=]

A unused static variable. It can simply be removed.

../../randr/rrcrtc.c:617:19: warning: argument 1 range [18446744073709551560, 18446744073709551608] exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
../../randr/rrcrtc.c:617:19: warning: argument 1 range [18446744073709551560, 18446744073709551608] exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]

These warnings are just because the compiler can't prove that the argument passed to malloc is less that PTRDIFF_MAX. It is probably not worth fixing, given that malloc will never be called with more that PTRDIFF_MAX.
The way to silence gcc, if that is desired, is to compare against PTRDIFF_MAX.

../../mi/miregion.c:339:5: warning: 'free' called on unallocated object 'miBrokenData' [-Wfree-nonheap-object]
../../mi/miregion.c:976:9: warning: 'free' called on unallocated object 'miEmptyData' [-Wfree-nonheap-object]
../../mi/miregion.c:994:9: warning: 'free' called on unallocated object 'miEmptyData' [-Wfree-nonheap-object]
../../mi/miregion.c:348:5: warning: 'free' called on unallocated object 'miBrokenData' [-Wfree-nonheap-object]
../../mi/miregion.c:976:9: warning: 'free' called on unallocated object 'miEmptyData' [-Wfree-nonheap-object]
../../mi/miregion.c:994:9: warning: 'free' called on unallocated object 'miEmptyData' [-Wfree-nonheap-object]
../../mi/miregion.c:339:5: warning: 'free' called on unallocated object 'miBrokenData' [-Wfree-nonheap-object]
../../mi/miregion.c:348:5: warning: 'free' called on unallocated object 'miBrokenData' [-Wfree-nonheap-object]

These are bogus warnings, as @clbr pointed out to me when I asked him. I also asked some gcc devs and they said that the reason these happen is because the compiler can't prove that free is never called on those unallocated objects. Maybe worth adding -Wno-free-nonheap-object to CFLAGS to silence the warning.

I can make a patch to fix these.
What do you think, are any of there warnings worth fixing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant