[PATCH 1/3] Mark tables, strings, arrays as constant where no real code is changed.
Diego Elio Pettenò
flameeyes at gmail.com
Fri Oct 1 16:47:59 CEST 2010
This patch changes as many data structures as possible to be constant (or
static constant) without any code change. The only change in non-structure
declaration is adapting the functions' parameters to accept the pointer to
constant (which is the stricter option).
---
agent/command-ssh.c | 8 ++++----
agent/gpg-agent.c | 2 +-
agent/preset-passphrase.c | 2 +-
agent/protect-tool.c | 2 +-
g10/armor.c | 8 ++++----
g10/gpg.c | 4 ++--
g10/gpgv.c | 2 +-
g10/main.h | 2 +-
g10/misc.c | 2 +-
jnlib/argparse.c | 12 ++++++------
jnlib/argparse.h | 4 ++--
kbx/kbxutil.c | 2 +-
scd/app-dinsig.c | 6 +++---
scd/app-nks.c | 6 +++---
scd/app-openpgp.c | 16 ++++++++--------
scd/app-p15.c | 4 ++--
scd/sc-copykeys.c | 2 +-
scd/scdaemon.c | 2 +-
sm/base64.c | 4 ++--
sm/certreqgen.c | 6 +++---
sm/gpgsm.c | 2 +-
tools/gpg-check-pattern.c | 2 +-
tools/gpg-connect-agent.c | 2 +-
tools/gpgconf.c | 2 +-
tools/gpgsplit.c | 2 +-
tools/symcryptrun.c | 2 +-
26 files changed, 54 insertions(+), 54 deletions(-)
diff --git a/agent/command-ssh.c b/agent/command-ssh.c
index 12fe60a..d5ebfc4 100644
--- a/agent/command-ssh.c
+++ b/agent/command-ssh.c
@@ -198,7 +198,7 @@ static gpg_error_t ssh_signature_encoder_dsa (estream_t signature_blob,
/* Associating request types with the corresponding request
handlers. */
-static ssh_request_spec_t request_specs[] =
+static const ssh_request_spec_t request_specs[] =
{
#define REQUEST_SPEC_DEFINE(id, name, secret_input) \
{ SSH_REQUEST_##id, ssh_handler_##name, #name, secret_input }
@@ -2717,10 +2717,10 @@ ssh_handler_unlock (ctrl_t ctrl, estream_t request, estream_t response)
/* Return the request specification for the request identified by TYPE
or NULL in case the requested request specification could not be
found. */
-static ssh_request_spec_t *
+static const ssh_request_spec_t *
request_spec_lookup (int type)
{
- ssh_request_spec_t *spec;
+ const ssh_request_spec_t *spec;
unsigned int i;
for (i = 0; i < DIM (request_specs); i++)
@@ -2744,7 +2744,7 @@ request_spec_lookup (int type)
static int
ssh_request_process (ctrl_t ctrl, estream_t stream_sock)
{
- ssh_request_spec_t *spec;
+ const ssh_request_spec_t *spec;
estream_t response;
estream_t request;
unsigned char request_type;
diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index 7e35947..b05ad82 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -111,7 +111,7 @@ enum cmd_and_opt_values
-static ARGPARSE_OPTS opts[] = {
+static const ARGPARSE_OPTS opts[] = {
{ aGPGConfList, "gpgconf-list", 256, "@" },
{ aGPGConfTest, "gpgconf-test", 256, "@" },
diff --git a/agent/preset-passphrase.c b/agent/preset-passphrase.c
index 72de91b..0657252 100644
--- a/agent/preset-passphrase.c
+++ b/agent/preset-passphrase.c
@@ -67,7 +67,7 @@ aTest };
static const char *opt_homedir;
static const char *opt_passphrase;
-static ARGPARSE_OPTS opts[] = {
+static const ARGPARSE_OPTS opts[] = {
{ 301, NULL, 0, N_("@Options:\n ") },
diff --git a/agent/protect-tool.c b/agent/protect-tool.c
index dc040f9..fb2563e 100644
--- a/agent/protect-tool.c
+++ b/agent/protect-tool.c
@@ -109,7 +109,7 @@ static int store_private_key (const unsigned char *grip,
const void *buffer, size_t length, int force);
-static ARGPARSE_OPTS opts[] = {
+static const ARGPARSE_OPTS opts[] = {
ARGPARSE_group (300, N_("@Commands:\n ")),
ARGPARSE_c (oProtect, "protect", "protect a private key"),
diff --git a/g10/armor.c b/g10/armor.c
index 652ef3a..30213a2 100644
--- a/g10/armor.c
+++ b/g10/armor.c
@@ -46,9 +46,9 @@
a &= 0x00ffffff; \
} while(0)
static u32 crc_table[256];
-static byte bintoasc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz"
- "0123456789+/";
+static const byte bintoasc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789+/";
static byte asctobin[256]; /* runtime initialized */
static int is_initialized;
@@ -165,7 +165,7 @@ initialize(void)
{
int i, j;
u32 t;
- byte *s;
+ const byte *s;
/* init the crc lookup table */
crc_table[0] = 0;
diff --git a/g10/gpg.c b/g10/gpg.c
index 7e648fb..b2a0524 100644
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -368,7 +368,7 @@ enum cmd_and_opt_values
};
-static ARGPARSE_OPTS opts[] = {
+static const ARGPARSE_OPTS opts[] = {
ARGPARSE_group (300, N_("@Commands:\n ")),
@@ -2694,7 +2694,7 @@ main (int argc, char **argv)
break;
case oVerifyOptions:
{
- struct parse_options vopts[]=
+ static const struct parse_options vopts[]=
{
{"show-photos",VERIFY_SHOW_PHOTOS,NULL,
N_("display photo IDs during signature verification")},
diff --git a/g10/gpgv.c b/g10/gpgv.c
index 747b05f..cd4afd6 100644
--- a/g10/gpgv.c
+++ b/g10/gpgv.c
@@ -65,7 +65,7 @@ enum cmd_and_opt_values {
};
-static ARGPARSE_OPTS opts[] = {
+static const ARGPARSE_OPTS opts[] = {
ARGPARSE_group (300, N_("@\nOptions:\n ")),
ARGPARSE_s_n (oVerbose, "verbose", N_("verbose")),
diff --git a/g10/main.h b/g10/main.h
index 3a42137..49ebb16 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -138,7 +138,7 @@ struct parse_options
char *optsep(char **stringp);
char *argsplit(char *string);
int parse_options(char *str,unsigned int *options,
- struct parse_options *opts,int noisy);
+ const struct parse_options *opts,int noisy);
int has_invalid_email_chars (const char *s);
int is_valid_mailbox (const char *name);
const char *get_libexecdir (void);
diff --git a/g10/misc.c b/g10/misc.c
index 8cc63ba..9eb8b99 100644
--- a/g10/misc.c
+++ b/g10/misc.c
@@ -1120,7 +1120,7 @@ optlen(const char *s)
int
parse_options(char *str,unsigned int *options,
- struct parse_options *opts,int noisy)
+ const struct parse_options *opts,int noisy)
{
char *tok;
diff --git a/jnlib/argparse.c b/jnlib/argparse.c
index 8b2a9f4..7f9df26 100644
--- a/jnlib/argparse.c
+++ b/jnlib/argparse.c
@@ -146,7 +146,7 @@ struct alias_def_s {
static const char *(*strusage_handler)( int ) = NULL;
static int set_opt_arg(ARGPARSE_ARGS *arg, unsigned flags, char *s);
-static void show_help(ARGPARSE_OPTS *opts, unsigned flags);
+static void show_help(const ARGPARSE_OPTS *opts, unsigned flags);
static void show_version(void);
@@ -263,7 +263,7 @@ store_alias( ARGPARSE_ARGS *arg, char *name, char *value )
*/
int
optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
- ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts)
+ ARGPARSE_ARGS *arg, const ARGPARSE_OPTS *opts)
{
int state, i, c;
int idx=0;
@@ -508,7 +508,7 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
static int
find_long_option( ARGPARSE_ARGS *arg,
- ARGPARSE_OPTS *opts, const char *keyword )
+ const ARGPARSE_OPTS *opts, const char *keyword )
{
int i;
size_t n;
@@ -555,7 +555,7 @@ find_long_option( ARGPARSE_ARGS *arg,
}
int
-arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts)
+arg_parse( ARGPARSE_ARGS *arg, const ARGPARSE_OPTS *opts)
{
int idx;
int argc;
@@ -833,7 +833,7 @@ set_opt_arg(ARGPARSE_ARGS *arg, unsigned flags, char *s)
static size_t
-long_opt_strlen( ARGPARSE_OPTS *o )
+long_opt_strlen( const ARGPARSE_OPTS *o )
{
size_t n = strlen (o->long_opt);
@@ -872,7 +872,7 @@ long_opt_strlen( ARGPARSE_OPTS *o )
* bar and the next one as arguments of the long option.
*/
static void
-show_help (ARGPARSE_OPTS *opts, unsigned int flags)
+show_help (const ARGPARSE_OPTS *opts, unsigned int flags)
{
const char *s;
diff --git a/jnlib/argparse.h b/jnlib/argparse.h
index b211e5f..d06fa10 100644
--- a/jnlib/argparse.h
+++ b/jnlib/argparse.h
@@ -173,9 +173,9 @@ typedef struct
#define ARGPARSE_OUT_OF_CORE (-11)
-int arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
+int arg_parse( ARGPARSE_ARGS *arg, const ARGPARSE_OPTS *opts);
int optfile_parse( FILE *fp, const char *filename, unsigned *lineno,
- ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
+ ARGPARSE_ARGS *arg, const ARGPARSE_OPTS *opts);
void usage( int level );
const char *strusage( int level );
void set_strusage( const char *(*f)( int ) );
diff --git a/kbx/kbxutil.c b/kbx/kbxutil.c
index 4592811..66ca614 100644
--- a/kbx/kbxutil.c
+++ b/kbx/kbxutil.c
@@ -67,7 +67,7 @@ enum cmd_and_opt_values {
};
-static ARGPARSE_OPTS opts[] = {
+static const ARGPARSE_OPTS opts[] = {
{ 300, NULL, 0, N_("@Commands:\n ") },
/* { aFindByFpr, "find-by-fpr", 0, "|FPR| find key using it's fingerprnt" }, */
diff --git a/scd/app-dinsig.c b/scd/app-dinsig.c
index 46e9a6a..a9c78f2 100644
--- a/scd/app-dinsig.c
+++ b/scd/app-dinsig.c
@@ -393,13 +393,13 @@ do_sign (app_t app, const char *keyidstr, int hashalgo,
const void *indata, size_t indatalen,
unsigned char **outdata, size_t *outdatalen )
{
- static unsigned char sha1_prefix[15] = /* Object ID is 1.3.14.3.2.26 */
+ static const unsigned char sha1_prefix[15] = /* Object ID is 1.3.14.3.2.26 */
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 };
- static unsigned char rmd160_prefix[15] = /* Object ID is 1.3.36.3.2.1 */
+ static const unsigned char rmd160_prefix[15] = /* Object ID is 1.3.36.3.2.1 */
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x24, 0x03,
0x02, 0x01, 0x05, 0x00, 0x04, 0x14 };
- static unsigned char sha256_prefix[19] = /* OID is 2.16.840.1.101.3.4.2.1 */
+ static const unsigned char sha256_prefix[19] = /* OID is 2.16.840.1.101.3.4.2.1 */
{ 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
0x00, 0x04, 0x20 };
diff --git a/scd/app-nks.c b/scd/app-nks.c
index 076b913..068ccef 100644
--- a/scd/app-nks.c
+++ b/scd/app-nks.c
@@ -333,7 +333,7 @@ do_getattr (app_t app, ctrl_t ctrl, const char *name)
signing. it might work anyway but it has not yet been
tested - fixme. Thus for now we use the NKS signature key
for authentication. */
- char const tmp[] = "NKS-NKS3.4531";
+ static const char tmp[] = "NKS-NKS3.4531";
send_status_info (ctrl, table[idx].name, tmp, strlen (tmp), NULL, 0);
}
break;
@@ -852,10 +852,10 @@ do_sign (app_t app, const char *keyidstr, int hashalgo,
const void *indata, size_t indatalen,
unsigned char **outdata, size_t *outdatalen )
{
- static unsigned char sha1_prefix[15] = /* Object ID is 1.3.14.3.2.26 */
+ static const unsigned char sha1_prefix[15] = /* Object ID is 1.3.14.3.2.26 */
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 };
- static unsigned char rmd160_prefix[15] = /* Object ID is 1.3.36.3.2.1 */
+ static const unsigned char rmd160_prefix[15] = /* Object ID is 1.3.36.3.2.1 */
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x24, 0x03,
0x02, 0x01, 0x05, 0x00, 0x04, 0x14 };
int rc, i;
diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c
index d468591..eed6600 100644
--- a/scd/app-openpgp.c
+++ b/scd/app-openpgp.c
@@ -69,7 +69,7 @@
/* A table describing the DOs of the card. */
-static struct {
+static const struct {
int tag;
int constructed;
int get_from; /* Constructed DO with this DO or 0 for direct access. */
@@ -84,7 +84,7 @@ static struct {
status bytes. */
int try_extlen:1; /* Large object; try to use an extended
length APDU. */
- char *desc;
+ const char *desc;
} data_objects[] = {
{ 0x005E, 0, 0, 1, 0, 0, 0, 0, "Login Data" },
{ 0x5F50, 0, 0, 0, 0, 0, 0, 0, "URL" },
@@ -3026,25 +3026,25 @@ do_sign (app_t app, const char *keyidstr, int hashalgo,
const void *indata, size_t indatalen,
unsigned char **outdata, size_t *outdatalen )
{
- static unsigned char rmd160_prefix[15] = /* Object ID is 1.3.36.3.2.1 */
+ static const unsigned char rmd160_prefix[15] = /* Object ID is 1.3.36.3.2.1 */
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x24, 0x03,
0x02, 0x01, 0x05, 0x00, 0x04, 0x14 };
- static unsigned char sha1_prefix[15] = /* (1.3.14.3.2.26) */
+ static const unsigned char sha1_prefix[15] = /* (1.3.14.3.2.26) */
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 };
- static unsigned char sha224_prefix[19] = /* (2.16.840.1.101.3.4.2.4) */
+ static const unsigned char sha224_prefix[19] = /* (2.16.840.1.101.3.4.2.4) */
{ 0x30, 0x2D, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48,
0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 0x00, 0x04,
0x1C };
- static unsigned char sha256_prefix[19] = /* (2.16.840.1.101.3.4.2.1) */
+ static const unsigned char sha256_prefix[19] = /* (2.16.840.1.101.3.4.2.1) */
{ 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
0x00, 0x04, 0x20 };
- static unsigned char sha384_prefix[19] = /* (2.16.840.1.101.3.4.2.2) */
+ static const unsigned char sha384_prefix[19] = /* (2.16.840.1.101.3.4.2.2) */
{ 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05,
0x00, 0x04, 0x30 };
- static unsigned char sha512_prefix[19] = /* (2.16.840.1.101.3.4.2.3) */
+ static const unsigned char sha512_prefix[19] = /* (2.16.840.1.101.3.4.2.3) */
{ 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05,
0x00, 0x04, 0x40 };
diff --git a/scd/app-p15.c b/scd/app-p15.c
index 8322617..512476b 100644
--- a/scd/app-p15.c
+++ b/scd/app-p15.c
@@ -2850,10 +2850,10 @@ do_sign (app_t app, const char *keyidstr, int hashalgo,
const void *indata, size_t indatalen,
unsigned char **outdata, size_t *outdatalen )
{
- static unsigned char sha1_prefix[15] = /* Object ID is 1.3.14.3.2.26 */
+ static const unsigned char sha1_prefix[15] = /* Object ID is 1.3.14.3.2.26 */
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 };
- static unsigned char rmd160_prefix[15] = /* Object ID is 1.3.36.3.2.1 */
+ static const unsigned char rmd160_prefix[15] = /* Object ID is 1.3.36.3.2.1 */
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x24, 0x03,
0x02, 0x01, 0x05, 0x00, 0x04, 0x14 };
diff --git a/scd/sc-copykeys.c b/scd/sc-copykeys.c
index b863b01..b0a748c 100644
--- a/scd/sc-copykeys.c
+++ b/scd/sc-copykeys.c
@@ -50,7 +50,7 @@ enum cmd_and_opt_values
aTest };
-static ARGPARSE_OPTS opts[] = {
+static const ARGPARSE_OPTS opts[] = {
{ 301, NULL, 0, "@Options:\n " },
diff --git a/scd/scdaemon.c b/scd/scdaemon.c
index 5b7ecf2..8a0a3c5 100644
--- a/scd/scdaemon.c
+++ b/scd/scdaemon.c
@@ -96,7 +96,7 @@ enum cmd_and_opt_values
-static ARGPARSE_OPTS opts[] = {
+static const ARGPARSE_OPTS opts[] = {
ARGPARSE_c (aGPGConfList, "gpgconf-list", "@"),
ARGPARSE_c (aGPGConfTest, "gpgconf-test", "@"),
diff --git a/sm/base64.c b/sm/base64.c
index b0c8dc8..8b88821 100644
--- a/sm/base64.c
+++ b/sm/base64.c
@@ -103,12 +103,12 @@ struct base64_context_s {
/* The base-64 character list */
-static char bintoasc[64] =
+static const char bintoasc[64] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
/* The reverse base-64 list */
-static unsigned char asctobin[256] = {
+static const unsigned char asctobin[256] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
diff --git a/sm/certreqgen.c b/sm/certreqgen.c
index 49b2b92..57f9515 100644
--- a/sm/certreqgen.c
+++ b/sm/certreqgen.c
@@ -417,9 +417,9 @@ static int
has_invalid_email_chars (const char *s)
{
int at_seen=0;
- static char valid_chars[] = "01234567890_-."
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ static const char valid_chars[] = "01234567890_-."
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (; *s; s++)
{
if (*s & 0x80)
diff --git a/sm/gpgsm.c b/sm/gpgsm.c
index 6388d90..90e364e 100644
--- a/sm/gpgsm.c
+++ b/sm/gpgsm.c
@@ -181,7 +181,7 @@ enum cmd_and_opt_values {
};
-static ARGPARSE_OPTS opts[] = {
+static const ARGPARSE_OPTS opts[] = {
ARGPARSE_group (300, N_("@Commands:\n ")),
diff --git a/tools/gpg-check-pattern.c b/tools/gpg-check-pattern.c
index 8d15263..e797869 100644
--- a/tools/gpg-check-pattern.c
+++ b/tools/gpg-check-pattern.c
@@ -65,7 +65,7 @@ enum cmd_and_opt_values
/* The list of commands and options. */
-static ARGPARSE_OPTS opts[] = {
+static const ARGPARSE_OPTS opts[] = {
{ 301, NULL, 0, N_("@Options:\n ") },
diff --git a/tools/gpg-connect-agent.c b/tools/gpg-connect-agent.c
index 4acda01..dbc86aa 100644
--- a/tools/gpg-connect-agent.c
+++ b/tools/gpg-connect-agent.c
@@ -63,7 +63,7 @@ enum cmd_and_opt_values
/* The list of commands and options. */
-static ARGPARSE_OPTS opts[] = {
+static const ARGPARSE_OPTS opts[] = {
ARGPARSE_group (301, N_("@\nOptions:\n ")),
ARGPARSE_s_n (oVerbose, "verbose", N_("verbose")),
diff --git a/tools/gpgconf.c b/tools/gpgconf.c
index eb7e9c9..f8d1b2d 100644
--- a/tools/gpgconf.c
+++ b/tools/gpgconf.c
@@ -55,7 +55,7 @@ enum cmd_and_opt_values
/* The list of commands and options. */
-static ARGPARSE_OPTS opts[] =
+static const ARGPARSE_OPTS opts[] =
{
{ 300, NULL, 0, N_("@Commands:\n ") },
diff --git a/tools/gpgsplit.c b/tools/gpgsplit.c
index 3f093c3..f7b4902 100644
--- a/tools/gpgsplit.c
+++ b/tools/gpgsplit.c
@@ -63,7 +63,7 @@ enum cmd_and_opt_values {
};
-static ARGPARSE_OPTS opts[] = {
+static const ARGPARSE_OPTS opts[] = {
{ 301, NULL, 0, "@Options:\n " },
diff --git a/tools/symcryptrun.c b/tools/symcryptrun.c
index 7eeff97..f80522a 100644
--- a/tools/symcryptrun.c
+++ b/tools/symcryptrun.c
@@ -146,7 +146,7 @@ enum cmd_and_opt_values
/* The list of commands and options. */
-static ARGPARSE_OPTS opts[] =
+static const ARGPARSE_OPTS opts[] =
{
{ 301, NULL, 0, N_("@\nCommands:\n ") },
--
1.7.3.1
More information about the Gnupg-devel
mailing list