Re: [hackers] [dwm][PATCH RESEND 0/2] Const-correctness fixes

From: NRK <nrk_AT_disroot.org>
Date: Mon, 22 Aug 2022 14:01:25 +0600

On Sun, Aug 21, 2022 at 11:08:43PM +0100, Chris Down wrote:
> I originally sent these a few years ago and the reply was that
> const-correctness wasn't something cared about, but seeing other const
> changes in dwm, and purely const-correctness improvements in
> quark/st/libgrapheme, I figured maybe it's worth reevaluating and seeing
> if they are of interest now.

I would add the attached patch to the list as well.

String literals in C are of the type `char []`, however modifying them
is actually UB [0] and in practice it can even result in a segfault.

The `-Wwrite-strings` flag treats string literals as `const char []` and
thus warns about cases where a string literal gets assigned to a `char *`.

P.S: I didn't add the flag to config.mk/CFLAGS in the patch since
changing the default warning flags can be seen as an opinionated change.

[0]: https://port70.net/~nsz/c/c99/n1256.html#6.4.5p6

- NRK

Received on Mon Aug 22 2022 - 10:01:25 CEST

This archive was generated by hypermail 2.3.0 : Mon Aug 22 2022 - 10:12:39 CEST