[File] Remove memset() overhead
Christos Zoulas
christos at zoulas.com
Sat Oct 30 16:51:45 UTC 2021
Hi,
I am not sure I like this (as I am sitting on a quite large patch to do the opposite for the NetBSD kernel).
Performance aside, and it is implementation dependent which one is better because:
1. memset can be inlined
2. initializers can be implemented with code or with a template copy
It is unclear which one is going to be faster and the two methods will never be equivalent because of padding.
There is no way in C to initialize padding bytes that are added by the compiler to meet structure alignment constraints.
This can lead to memory disclosure issues (which is why NetBSD is using memset(3) and so did Linux a few years
ago). Although there are no significant memory disclosure issues in libmagic since all the structures are internal,
and they belong to the same process contexts, it is good practice to keep using memset(3).
Yes, there is an issue for weird architectures where the NULL pointer is not "all bits 0 pointer" or where the floating
point zero is not "the all bits 0, float, double, long double", but nobody builds such processors anymore.
So until the C standard changes in a way that uninitialized padding is handled properly, memset(3) it is.
Best
christos
> On Oct 29, 2021, at 12:59 AM, Avinash Sonawane <rootkea at gmail.com> wrote:
>
> Hello!
>
> Please find the attached patch which removes the memset() overhead.
>
> Thanks!
>
> Regards,
> Avinash Sonawane (rootKea)
> https://www.rootkea.me
> <0001-Remove-memset-overhead.patch>--
> File mailing list
> File at astron.com
> https://mailman.astron.com/mailman/listinfo/file
More information about the File
mailing list