[parted-devel] labels/*.c: Declare some static arrays to be "const".

Jim Meyering jim at meyering.net
Wed Mar 7 19:27:20 CET 2007


Making these tables "const" lets the compiler/linker put the values
in read-only storage.  Not only more efficient in some cases, but
also protects against accidental modification.

	Declare some static arrays to be "const".
	* libparted/labels/dos.c (MBR_BOOT_CODE):
	* libparted/labels/efi_crc32.c (crc32_tab):
	* libparted/labels/pc98.c (MBR_BOOT_CODE):
	* libparted/labels/vtoc.c (EBCtoASC, ASCtoEBC):

diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index 051d5ea..6547dd1 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -36,7 +36,7 @@
  * the source, and how to build it
  */

-static char MBR_BOOT_CODE[] = {
+static const char MBR_BOOT_CODE[] = {
 	0xfa, 0xb8, 0x00, 0x10, 0x8e, 0xd0, 0xbc, 0x00,
 	0xb0, 0xb8, 0x00, 0x00, 0x8e, 0xd8, 0x8e, 0xc0,
 	0xfb, 0xbe, 0x00, 0x7c, 0xbf, 0x00, 0x06, 0xb9,
diff --git a/libparted/labels/efi_crc32.c b/libparted/labels/efi_crc32.c
index 01cdff7..327fb2d 100644
--- a/libparted/labels/efi_crc32.c
+++ b/libparted/labels/efi_crc32.c
@@ -51,7 +51,7 @@
 #include <config.h>
 #include <stdint.h>

-static uint32_t crc32_tab[] = {
+static const uint32_t crc32_tab[] = {
       0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
       0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
       0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
diff --git a/libparted/labels/pc98.c b/libparted/labels/pc98.c
index 7312b6f..27f84a5 100644
--- a/libparted/labels/pc98.c
+++ b/libparted/labels/pc98.c
@@ -113,7 +113,7 @@ typedef struct {
 } PC98PartitionData;

 /* this MBR boot code is dummy */
-static char MBR_BOOT_CODE[] = {
+static const char MBR_BOOT_CODE[] = {
 	0xcb,			/* retf */
 	0x00, 0x00, 0x00,	/* */
 	0x49, 0x50, 0x4c, 0x31  /* "IPL1" */
diff --git a/libparted/labels/vtoc.c b/libparted/labels/vtoc.c
index 028f8b0..8ea4946 100644
--- a/libparted/labels/vtoc.c
+++ b/libparted/labels/vtoc.c
@@ -19,7 +19,7 @@
 #  define _(String) (String)
 #endif /* ENABLE_NLS */

-static unsigned char EBCtoASC[256] =
+static const unsigned char EBCtoASC[256] =
 {
 /* 0x00  NUL   SOH   STX   ETX  *SEL    HT  *RNL   DEL */
 	0x00, 0x01, 0x02, 0x03, 0x07, 0x09, 0x07, 0x7F,
@@ -91,7 +91,7 @@ static unsigned char EBCtoASC[256] =
 	0x38, 0x39, 0x07, 0x07, 0x9A, 0x07, 0x07, 0x07
 };

-static unsigned char ASCtoEBC[256] =
+static const unsigned char ASCtoEBC[256] =
 {
     /*00  NL    SH    SX    EX    ET    NQ    AK    BL */
 	0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F,



More information about the parted-devel mailing list