Skip to content

Commit 2699c87

Browse files
author
MDW
committed
qual: Fix multiple 'obvious' cppcheck notices.
1 parent 7abfe7a commit 2699c87

19 files changed

Lines changed: 62 additions & 56 deletions

access.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static int match_address(const char *addr, char *tok)
112112
int bits;
113113
#endif
114114
char mask[16];
115-
char *a = NULL, *t = NULL;
115+
const char *a = NULL, *t = NULL;
116116

117117
if (!addr || !*addr)
118118
return 0;

batch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void check_batch_flags(void)
132132
tweaked_iconv = iconv_opt != NULL;
133133
#endif
134134
for (i = 0; flag_ptr[i]; i++) {
135-
int set = batch_stream_flags & (1 << i) ? 1 : 0;
135+
int set = (batch_stream_flags & (1 << i)) ? 1 : 0;
136136
if (*flag_ptr[i] != set) {
137137
if (i == 9) {
138138
rprintf(FERROR,

checksum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ uint32 get_checksum1(char *buf1, int32 len)
286286
{
287287
int32 i;
288288
uint32 s1, s2;
289-
schar *buf = (schar *)buf1;
289+
const schar *buf = (schar *)buf1;
290290

291291
s1 = s2 = 0;
292292
for (i = 0; i < (len-4); i+=4) {

clientserver.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ int start_socket_client(char *host, int remote_argc, char *remote_argv[],
119119
int argc, char *argv[])
120120
{
121121
int fd, ret;
122-
char *p, *user = NULL;
122+
char *p;
123+
const char *user = NULL;
123124

124125
/* This is redundant with code in start_inband_exchange(), but this
125126
* short-circuits a problem in the client before we open a socket,
@@ -156,7 +157,7 @@ static int exchange_protocols(int f_in, int f_out, char *buf, size_t bufsiz, int
156157

157158
output_daemon_greeting(f_out, am_client);
158159
if (!am_client) {
159-
char *motd = lp_motd_file();
160+
const char *motd = lp_motd_file();
160161
if (motd && *motd) {
161162
FILE *f = fopen(motd, "r");
162163
while (f && !feof(f)) {
@@ -323,7 +324,7 @@ int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char
323324
} while ((p = strstr(p+1, line)) != NULL);
324325
}
325326
if (extra_chars) {
326-
char *f = arg;
327+
const char *f = arg;
327328
char *t = arg = new_array(char, strlen(arg) + extra_chars + 1);
328329
if (*f == '-') {
329330
*t++ = '.';
@@ -1155,9 +1156,9 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char
11551156
* Without this, the socket would be in the wrong
11561157
* state for the upcoming error message. */
11571158
if (!files_from) {
1158-
int i;
1159-
for (i = 0; i < argc; i++) {
1160-
if (strncmp(argv[i], "--files-from", 12) == 0) {
1159+
int arg_idx;
1160+
for (arg_idx = 0; arg_idx < argc; arg_idx++) {
1161+
if (strncmp(argv[arg_idx], "--files-from", 12) == 0) {
11611162
files_from = "";
11621163
break;
11631164
}

compat.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void parse_compress_choice(int final_call)
184184
if (valid_compressions.negotiated_nni)
185185
do_compression = valid_compressions.negotiated_nni->num;
186186
else if (compress_choice) {
187-
struct name_num_item *nni = get_nni_by_name(&valid_compressions, compress_choice, -1);
187+
struct name_num_item const * const nni = get_nni_by_name(&valid_compressions, compress_choice, -1);
188188
if (!nni) {
189189
rprintf(FERROR, "unknown compress name: %s\n", compress_choice);
190190
exit_cleanup(RERR_UNSUPPORTED);
@@ -292,7 +292,7 @@ static int parse_nni_str(struct name_num_obj *nno, const char *from, char *tobuf
292292
ch = '\0';
293293
if (!ch || at_space) {
294294
if (tok) {
295-
struct name_num_item *nni = get_nni_by_name(nno, tok, to - tok);
295+
struct name_num_item const * const nni = get_nni_by_name(nno, tok, to - tok);
296296
if (nni && !nno->saw[nni->num]) {
297297
nno->saw[nni->num] = ++cnt;
298298
if (nni->main_nni) {
@@ -743,11 +743,11 @@ void setup_protocol(int f_out,int f_in)
743743
do_negotiated_strings = 1;
744744
}
745745
/* The inc_recurse var MUST be set to 0 or 1. */
746-
inc_recurse = compat_flags & CF_INC_RECURSE ? 1 : 0;
746+
inc_recurse = (compat_flags & CF_INC_RECURSE) ? 1 : 0;
747747
want_xattr_optim = protocol_version >= 31 && !(compat_flags & CF_AVOID_XATTR_OPTIM);
748-
proper_seed_order = compat_flags & CF_CHKSUM_SEED_FIX ? 1 : 0;
749-
xfer_flags_as_varint = compat_flags & CF_VARINT_FLIST_FLAGS ? 1 : 0;
750-
xmit_id0_names = compat_flags & CF_ID0_NAMES ? 1 : 0;
748+
proper_seed_order = (compat_flags & CF_CHKSUM_SEED_FIX) ? 1 : 0;
749+
xfer_flags_as_varint = (compat_flags & CF_VARINT_FLIST_FLAGS) ? 1 : 0;
750+
xmit_id0_names = (compat_flags & CF_ID0_NAMES) ? 1 : 0;
751751
if (!xfer_flags_as_varint && preserve_crtimes) {
752752
fprintf(stderr, "Both rsync versions must be at least 3.2.0 for --crtimes.\n");
753753
exit_cleanup(RERR_PROTOCOL);

exclude.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ void *push_local_filters(const char *dir, unsigned int dirlen)
778778

779779
push->mergelist_cnt = mergelist_cnt;
780780
for (i = 0; i < mergelist_cnt; i++) {
781-
filter_rule *ex = mergelist_parents[i];
781+
const filter_rule *ex = mergelist_parents[i];
782782
if (!ex)
783783
continue;
784784
memcpy(&push->mergelists[i], ex->u.mergelist, sizeof (filter_rule_list));
@@ -903,15 +903,15 @@ void change_local_filter_dir(const char *dname, int dlen, int dir_depth)
903903
static int rule_matches(const char *fname, filter_rule *ex, int name_flags)
904904
{
905905
int slash_handling, str_cnt = 0, anchored_match = 0;
906-
int ret_match = ex->rflags & FILTRULE_NEGATE ? 0 : 1;
906+
int ret_match = (ex->rflags & FILTRULE_NEGATE) ? 0 : 1;
907907
const char *p, *pattern = ex->pattern;
908908
const char *strings[16]; /* more than enough */
909909
const char *name = fname + (*fname == '/');
910910

911-
if (!*name || ex->elide == cur_elide_value)
911+
if (!*name || (ex->elide == cur_elide_value))
912912
return 0;
913913

914-
if (!(name_flags & NAME_IS_XATTR) ^ !(ex->rflags & FILTRULE_XATTR))
914+
if (!(name_flags & NAME_IS_XATTR) != !(ex->rflags & FILTRULE_XATTR))
915915
return 0;
916916

917917
if (!ex->u.slash_cnt && !(ex->rflags & FILTRULE_WILD2)) {
@@ -1057,7 +1057,7 @@ int check_filter(filter_rule_list *listp, enum logcode code,
10571057
}
10581058
if (rule_matches(name, ent, name_flags)) {
10591059
report_filter_result(code, name, ent, name_flags, listp->debug_type);
1060-
return ent->rflags & FILTRULE_INCLUDE ? 1 : -1;
1060+
return (ent->rflags & FILTRULE_INCLUDE) ? 1 : -1;
10611061
}
10621062
}
10631063

@@ -1448,7 +1448,7 @@ void parse_filter_file(filter_rule_list *listp, const char *fname, const filter_
14481448
{
14491449
FILE *fp;
14501450
char line[BIGPATHBUFLEN];
1451-
char *eob = line + sizeof line - 1;
1451+
const char *eob = line + sizeof line - 1;
14521452
BOOL word_split = (template->rflags & FILTRULE_WORD_SPLIT) != 0;
14531453

14541454
if (!fname || !*fname)
@@ -1629,7 +1629,7 @@ static void send_rules(int f_out, filter_rule_list *flp)
16291629
if (f_out < 0)
16301630
continue;
16311631
len = strlen(ent->pattern);
1632-
dlen = ent->rflags & FILTRULE_DIRECTORY ? 1 : 0;
1632+
dlen = (ent->rflags & FILTRULE_DIRECTORY) ? 1 : 0;
16331633
if (!(plen + len + dlen))
16341634
continue;
16351635
write_int(f_out, plen + len + dlen);

getgroups.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
int main(UNUSED(int argc), UNUSED(char *argv[]))
2424
{
2525
int n, i;
26-
gid_t *list;
26+
const gid_t *list;
2727
gid_t gid = MY_GID();
2828
int gid_in_list = 0;
2929

loadparm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static char *expand_vars(const char *str)
180180
if (*f == '%' && isUpper(f+1)) {
181181
const char *percent = strchr(f+1, '%');
182182
if (percent && percent - f < bufsize) {
183-
char *val;
183+
const char *val;
184184
strlcpy(t, f+1, percent - f);
185185
val = getenv(t);
186186
if (val) {
@@ -485,7 +485,7 @@ static BOOL do_section(char *sectionname)
485485
memcpy(vp, &Vars, sizeof Vars);
486486
} else if (strcmp(sectionname+1, "pop") == 0
487487
|| strcmp(sectionname+1, "reset") == 0) {
488-
all_vars *vp = ((all_vars*)Vars_stack.items) + Vars_stack.count - 1;
488+
const all_vars *vp = ((all_vars*)Vars_stack.items) + Vars_stack.count - 1;
489489
if (!Vars_stack.count)
490490
return False;
491491
memcpy(&Vars, vp, sizeof Vars);

main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static void become_copy_as_user()
272272
exit_cleanup(RERR_SYNTAX);
273273
}
274274
} else {
275-
struct passwd *pw;
275+
const struct passwd *pw;
276276
if ((pw = getpwuid(uid)) == NULL) {
277277
rsyserr(FERROR, errno, "getpwuid failed");
278278
exit_cleanup(RERR_SYNTAX);
@@ -925,7 +925,7 @@ static void read_final_goodbye(int f_in, int f_out)
925925

926926
static void do_server_sender(int f_in, int f_out, int argc, char *argv[])
927927
{
928-
struct file_list *flist;
928+
const struct file_list *flist;
929929
char *dir;
930930

931931
if (DEBUG_GTE(SEND, 1))
@@ -1284,7 +1284,7 @@ void start_server(int f_in, int f_out, int argc, char *argv[])
12841284
* for rsyncd, remote-shell, and local connections. */
12851285
int client_run(int f_in, int f_out, pid_t pid, int argc, char *argv[])
12861286
{
1287-
struct file_list *flist = NULL;
1287+
struct file_list *flist;
12881288
int exit_code = 0, exit_code2 = 0;
12891289
char *local_name = NULL;
12901290

options.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ static void output_item_help(struct output_struct *words)
485485
{
486486
short *levels = words == info_words ? info_levels : debug_levels;
487487
const char *const*verbosity = words == info_words ? info_verbosity : debug_verbosity;
488-
char buf[128], *opt, *fmt = "%-10s %s\n";
488+
char buf[128], *opt;
489+
static const char * const fmt = "%-10s %s\n";
489490
int j;
490491

491492
reset_output_levels();
@@ -943,7 +944,8 @@ static void parse_one_refuse_match(int negated, const char *ref, const struct po
943944
**/
944945
static void set_refuse_options(void)
945946
{
946-
struct poptOption *op, *list_end = NULL;
947+
struct poptOption *op;
948+
struct poptOption const *list_end = NULL;
947949
char *cp, *ref = lp_refuse_options(module_id);
948950
int negated;
949951

@@ -2871,7 +2873,7 @@ void server_options(char **args, int *argc_p)
28712873
args[ac++] = "--ignore-missing-args";
28722874

28732875
if (modify_window_set && am_sender) {
2874-
char *fmt = modify_window < 0 ? "-@%d" : "--modify-window=%d";
2876+
const char *fmt = modify_window < 0 ? "-@%d" : "--modify-window=%d";
28752877
if (asprintf(&arg, fmt, modify_window) < 0)
28762878
goto oom;
28772879
args[ac++] = arg;

0 commit comments

Comments
 (0)