Skip to content

Commit cd2f6cc

Browse files
visitorckwG36maid
authored andcommitted
Constify error_desc and perror
The error_desc array and the perror pointer are never modified after initialization. Marking them as const moves the data to the read-only section, improving safety. Before: $ riscv-none-elf-size ./build/kernel/error.o text data bss dec hex filename 398 172 0 570 23a ./build/kernel/error.o After: $ riscv-none-elf-size ./build/kernel/error.o text data bss dec hex filename 570 0 0 570 23a ./build/kernel/error.o
1 parent c5c8369 commit cd2f6cc

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

include/private/error.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ struct error_code {
3939
char *const desc;
4040
};
4141

42+
<<<<<<< HEAD
4243
extern const struct error_code *const perror;
44+
=======
45+
extern const struct error_code * const perror;
46+
>>>>>>> de976a5 (Constify error_desc and perror)

kernel/error.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ static const struct error_code error_desc[] = {
3535
{ERR_UNKNOWN, "unknown error"},
3636
};
3737

38+
<<<<<<< HEAD
3839
const struct error_code *const perror = error_desc;
40+
=======
41+
const struct error_code * const perror = error_desc;
42+
>>>>>>> de976a5 (Constify error_desc and perror)

0 commit comments

Comments
 (0)