[Toybox] [PATCH] tar: fix warn_unused_result error.

Rob Landley rob at landley.net
Thu Sep 2 09:59:58 PDT 2021


On 9/1/21 11:34 AM, Rob Landley wrote:
> I thought about typecasting it to (void) but decided to wait for a complaint
> because A)
> "CROSS_COMPILE=~/android/android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-
> make distclean defconfig toybox" didn't warn about it (obviously -Wall doesn't
> mean all, that would be silly),

So looking into this, there isn't a -Wunused-result or similar, it's that you
have to annotate every function you want to generate this warning for with
__attribute__((warn_unused_result)) and the NDK headers don't.

Well, there's a little annotation, via:

sysroot/usr/include/sys/cdefs.h has
#define __wur __attribute__((__warn_unused_result__))

Which then appears in three other files:

sysroot/usr/include/stdlib.h
sysroot/usr/include/malloc.h
sysroot/usr/include/sys/random.h

I.E.

sysroot/usr/include/stdlib.h:__wur char* realpath(const char* __path, char*
__resolved);
sysroot/usr/include/malloc.h:void* malloc(size_t __byte_count) __mallocfunc
__BIONIC_ALLOC_SIZE(1) __wur;
sysroot/usr/include/malloc.h:void* calloc(size_t __item_count, size_t
__item_size) __mallocfunc __BIONIC_ALLOC_SIZE(1,2) __wur;
sysroot/usr/include/malloc.h:void* realloc(void* __ptr, size_t __byte_count)
__BIONIC_ALLOC_SIZE(2) __wur;
sysroot/usr/include/malloc.h:void* reallocarray(void* __ptr, size_t
__item_count, size_t __item_size) __BIONIC_ALLOC_SIZE(2, 3) __wur
__INTRODUCED_IN(29);
sysroot/usr/include/malloc.h:void* memalign(size_t __alignment, size_t
__byte_count) __mallocfunc __BIONIC_ALLOC_SIZE(2) __wur;
sysroot/usr/include/sys/random.h:int getentropy(void* __buffer, size_t
__buffer_size) __wur __INTRODUCED_IN(28);
sysroot/usr/include/sys/random.h:ssize_t getrandom(void* __buffer, size_t
__buffer_size, unsigned int __flags) __wur __INTRODUCED_IN(28);

None of which is write().

That's why android-ndk-r21d isn't producing this warning. Would upgrading to a
newer version get it, or is this more aosp-vs-ndk version skew? (And is there an
easy way to build external packages with the AOSP prebuilt toolchain?)

Rob



More information about the Toybox mailing list