Skip to content

Commit

Permalink
Make arguments of strings const where appropriate to avoid having to
Browse files Browse the repository at this point in the history
cast "asedf" to (char *)"asedf".

Check returns or:

    vsnprintf

    write <- wrap in function that acutaully garentees the full write or
    returns an error.
  • Loading branch information
amishHammer committed Aug 11, 2011
1 parent 83fd256 commit 962ec7e
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 131 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -10,7 +10,7 @@ LIB = libcli.so
CC = gcc
DEBUG = -g
OPTIM = -O3
CFLAGS += $(DEBUG) $(OPTIM) -Wall -Wformat-security -Wno-format-zero-length
CFLAGS += $(DEBUG) $(OPTIM) -Wall -std=c99 -pedantic -Wformat-security -Wno-format-zero-length -Werror -Wwrite-strings -Wformat -fdiagnostics-show-option -Wextra -Wsign-compare -Wcast-align -Wno-unused-parameter
LDFLAGS += -shared
LIBPATH += -L.

Expand Down
21 changes: 11 additions & 10 deletions clitest.c
Expand Up @@ -9,6 +9,7 @@
#include <arpa/inet.h>
#endif
#include <signal.h>
#include <strings.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
Expand Down Expand Up @@ -61,7 +62,7 @@ int winsock_init()
}
#endif

int cmd_test(struct cli_def *cli, char *command, char *argv[], int argc)
int cmd_test(struct cli_def *cli, const char *command, char *argv[], int argc)
{
int i;
cli_print(cli, "called %s with \"%s\"", __FUNCTION__, command);
Expand All @@ -72,7 +73,7 @@ int cmd_test(struct cli_def *cli, char *command, char *argv[], int argc)
return CLI_OK;
}

int cmd_set(struct cli_def *cli, UNUSED(char *command), char *argv[],
int cmd_set(struct cli_def *cli, UNUSED(const char *command), char *argv[],
int argc)
{
if (argc < 2 || strcmp(argv[0], "?") == 0)
Expand All @@ -95,7 +96,7 @@ int cmd_set(struct cli_def *cli, UNUSED(char *command), char *argv[],
cli_print(cli, "Specify a regular callback interval in seconds");
return CLI_OK;
}
sscanf(argv[1], "%d", &sec);
sscanf(argv[1], "%u", &sec);
if (sec < 1)
{
cli_print(cli, "Specify a regular callback interval in seconds");
Expand All @@ -111,7 +112,7 @@ int cmd_set(struct cli_def *cli, UNUSED(char *command), char *argv[],
return CLI_OK;
}

int cmd_config_int(struct cli_def *cli, UNUSED(char *command), char *argv[],
int cmd_config_int(struct cli_def *cli, UNUSED(const char *command), char *argv[],
int argc)
{
if (argc < 1)
Expand All @@ -131,27 +132,27 @@ int cmd_config_int(struct cli_def *cli, UNUSED(char *command), char *argv[],
return CLI_OK;
}

int cmd_config_int_exit(struct cli_def *cli, UNUSED(char *command),
int cmd_config_int_exit(struct cli_def *cli, UNUSED(const char *command),
UNUSED(char *argv[]), UNUSED(int argc))
{
cli_set_configmode(cli, MODE_CONFIG, NULL);
return CLI_OK;
}

int cmd_show_regular(struct cli_def *cli, UNUSED(char *command), char *argv[], int argc)
int cmd_show_regular(struct cli_def *cli, UNUSED(const char *command), char *argv[], int argc)
{
cli_print(cli, "cli_regular() has run %u times", regular_count);
return CLI_OK;
}

int cmd_debug_regular(struct cli_def *cli, UNUSED(char *command), char *argv[], int argc)
int cmd_debug_regular(struct cli_def *cli, UNUSED(const char *command), char *argv[], int argc)
{
debug_regular = !debug_regular;
cli_print(cli, "cli_regular() debugging is %s", debug_regular ? "enabled" : "disabled");
return CLI_OK;
}

int check_auth(char *username, char *password)
int check_auth(const char *username, const char *password)
{
if (strcasecmp(username, "fred") != 0)
return CLI_ERROR;
Expand All @@ -171,7 +172,7 @@ int regular_callback(struct cli_def *cli)
return CLI_OK;
}

int check_enable(char *password)
int check_enable(const char *password)
{
return !strcasecmp(password, "topsecret");
}
Expand All @@ -182,7 +183,7 @@ int idle_timeout(struct cli_def *cli)
return CLI_QUIT;
}

void pc(UNUSED(struct cli_def *cli), char *string)
void pc(UNUSED(struct cli_def *cli), const char *string)
{
printf("%s\n", string);
}
Expand Down

0 comments on commit 962ec7e

Please sign in to comment.