Skip to content

Use const whenever we point to literal strings (take 1)

Julien Grall xen-devel 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 4 repliesIn review
  2. v114 patches 34 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2xen/char: console: Use const whenever we point to literal stringsxen/drivers/char/console.c+4 -32 replies
2/2tools/console: Use const whenever we point to literal stringstools/console/client/main.c tools/console/daemon/io.c+10 -91 reply

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchWei LiuLuca FancelluJan BeulichAnthony PERARD
1/2R-b R-b
2/2A-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v2 thread

Cover letter [PATCH v2 0/2] Use const whenever we point to literal strings (take 1)

From: Julien Grall <[email protected]>

Hi all,

By default, both Clang and GCC will happily compile C code where non-const char * point to literal strings. This means the following code will be accepted:

    char *str = "test";

    str[0] = 'a';

Literal strings will reside in rodata, so they are not modifiable. This will result to an permission fault at runtime if the permissions are enforced in the page-tables (this is the case in Xen).

I am not aware of code trying to modify literal strings in Xen. However, there is a frequent use of non-const char * to point to literal strings. Given the size of the codebase, there is a risk to involuntarily introduce code that will modify literal strings.

Therefore it would be better to enforce using const when pointing to such strings. Both GCC and Clang provide an option to warn for such case (see -Wwrite-strings) and therefore could be used by Xen.

This series doesn't yet make use of -Wwrite-strings because the tree is not fully converted. Instead, it contains some easy and non-controversial use of const in the code.

Julien Grall (2):
xen/char: console: Use const whenever we point to literal strings tools/console: Use const whenever we point to literal strings

 tools/console/client/main.c |  4 ++--
 tools/console/daemon/io.c   | 15 ++++++++-------
 xen/drivers/char/console.c  |  7 ++++---
 3 files changed, 14 insertions(+), 12 deletions(-)
Signature · 1 line
2.17.1