Re: [PATCH 6/7] CLI: make static message strings const
On Fri, May 14 2021, David Bremner wrote: > Tomi Ollila writes: > >> >> In my projects I've been using the following macro: >> #define WriteCS(fd, str) write((fd), (str), sizeof(str) - 1) >> but I don't know if that behaved any better (if we cared)... > > I'm not sure. The sizeof here is actually slightly treacherous (iiuc, > making things const char * will blow up the world) so I prefer it out in > the open. Right, const char * would make sizeof 8 (or 4). (I just fixed bug somewhere where first 4 chars of strings were compared for equality ;/). The WriteCS meant (Const String), perhaps LS (Literal String) would be better. (and write((fd), "" str "", sizeof(str) - 1)). ... have to check if this works, and start using if it works as expected! Tomi > >> But, in addition to these two identical copies of handle_sigint() >> also notmuch-new.c and notmuch-reindex.c defines anoter 2 identical >> copies of handle_sigint()... >> >> I did not see that those two were also modified in this series... > > Good catch! I did the same for those two and pushed the modified series. ___ notmuch mailing list -- notmuch@notmuchmail.org To unsubscribe send an email to notmuch-le...@notmuchmail.org
Re: [PATCH 6/7] CLI: make static message strings const
Tomi Ollila writes: > > In my projects I've been using the following macro: > #define WriteCS(fd, str) write((fd), (str), sizeof(str) - 1) > but I don't know if that behaved any better (if we cared)... I'm not sure. The sizeof here is actually slightly treacherous (iiuc, making things const char * will blow up the world) so I prefer it out in the open. > But, in addition to these two identical copies of handle_sigint() > also notmuch-new.c and notmuch-reindex.c defines anoter 2 identical > copies of handle_sigint()... > > I did not see that those two were also modified in this series... Good catch! I did the same for those two and pushed the modified series. ___ notmuch mailing list -- notmuch@notmuchmail.org To unsubscribe send an email to notmuch-le...@notmuchmail.org
[PATCH 6/7] CLI: make static message strings const
This is both a bit clearer and avoids the possibility of modification. --- notmuch-insert.c | 2 +- notmuch-tag.c| 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/notmuch-insert.c b/notmuch-insert.c index 00c00468..e3d87e4a 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -34,7 +34,7 @@ static volatile sig_atomic_t interrupted; static void handle_sigint (unused (int sig)) { -static char msg[] = "Stopping... \n"; +static const char msg[] = "Stopping... \n"; /* This write is "opportunistic", so it's okay to ignore the * result. It is not required for correctness, and if it does diff --git a/notmuch-tag.c b/notmuch-tag.c index 667a75d6..de428c8e 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -27,7 +27,7 @@ static volatile sig_atomic_t interrupted; static void handle_sigint (unused (int sig)) { -static char msg[] = "Stopping... \n"; +static const char msg[] = "Stopping... \n"; /* This write is "opportunistic", so it's okay to ignore the * result. It is not required for correctness, and if it does -- 2.30.2 ___ notmuch mailing list -- notmuch@notmuchmail.org To unsubscribe send an email to notmuch-le...@notmuchmail.org