Remove useless assignments
PATCH 1/1 Remove useless assignments
archive.c +1 -1
@@ -503,7 +503,7 @@ int write_archive(int argc, const char **argv, const char *prefix,init_tar_archiver ();init_zip_archiver (); - argc =parse_archive_args (argc, argv, &ar, &args, name_hint, remote); +parse_archive_args (argc, argv, &ar, &args, name_hint, remote);if (!startup_info->have_repository) {/* * We know this will die() with an error, so we could just
builtin/add.c +1 -1
@@ -211,7 +211,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)init_revisions (&rev, prefix); rev.diffopt.context =7 ; - argc =setup_revisions (argc, argv, &rev,NULL ); +setup_revisions (argc, argv, &rev,NULL ); rev.diffopt.output_format =DIFF_FORMAT_PATCH ; rev.diffopt.use_color =0 ;DIFF_OPT_SET (&rev.diffopt,IGNORE_DIRTY_SUBMODULES );
builtin/help.c +1 -1
@@ -453,7 +453,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)int nongit;enum help_format parsed_help_format; - argc =parse_options (argc, argv, prefix, builtin_help_options, +parse_options (argc, argv, prefix, builtin_help_options, builtin_help_usage,0 ); parsed_help_format = help_format;
builtin/merge.c +1 -1
@@ -795,7 +795,7 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)write_tree_trivial (&result_tree);printf (_ ("Wonderful.\n" )); pptr =commit_list_append (head, pptr); - pptr =commit_list_append (remoteheads->item, pptr); +commit_list_append (remoteheads->item, pptr);prepare_to_commit (remoteheads);if (commit_tree (merge_msg.buf, merge_msg.len, result_tree.hash, parents, result_commit.hash,NULL , sign_commit))
builtin/notes.c +1 -1
@@ -1015,7 +1015,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)else if (!strcmp (argv[0 ],"get-ref" )) result =get_ref (argc, argv, prefix);else { - result =error (_ ("unknown subcommand: %s" ), argv[0 ]); +error (_ ("unknown subcommand: %s" ), argv[0 ]);usage_with_options (git_notes_usage, options); }
builtin/prune-packed.c +1 -1
@@ -59,7 +59,7 @@ int cmd_prune_packed(int argc, const char **argv, const char *prefix) OPT_END() }; - argc =parse_options (argc, argv, prefix, prune_packed_options, +parse_options (argc, argv, prefix, prune_packed_options, prune_packed_usage,0 );prune_packed_objects (opts);
builtin/receive-pack.c +1 -1
@@ -498,7 +498,7 @@ static const char *check_nonce(const char *buf, size_t len)char *nonce =find_header (buf, len,"nonce" );timestamp_t stamp, ostamp;char *bohmac, *expect =NULL ; -const char *retval =NONCE_BAD ; +const char *retval;if (!nonce) { retval =NONCE_MISSING ;
builtin/reset.c +1 -1
@@ -291,7 +291,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)git_config (git_default_config,NULL ); - argc =parse_options (argc, argv, prefix, options, git_reset_usage, +parse_options (argc, argv, prefix, options, git_reset_usage,PARSE_OPT_KEEP_DASHDASH );parse_args (&pathspec, argv, prefix, patch_mode, &rev);
diffcore-rename.c +1 -1
@@ -580,7 +580,7 @@ void diffcore_rename(struct diff_options *options) rename_count +=find_renames (mx, dst_cnt, minimum_score,0 );if (detect_rename ==DIFF_DETECT_COPY ) - rename_count +=find_renames (mx, dst_cnt, minimum_score,1 ); +find_renames (mx, dst_cnt, minimum_score,1 );free (mx); cleanup:
fast-import.c +1 -1
@@ -2054,7 +2054,7 @@ static int validate_raw_date(const char *src, struct strbuf *result) errno =0 ; - num =strtoul (src, &endp,10 ); +strtoul (src, &endp,10 );/* NEEDSWORK: perhaps check for reasonable values? */ if (errno || endp == src || *endp !=' ' )return -1 ;
fsck.c +0 -1
@@ -703,7 +703,6 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option !isdigit(p[4]) || (p[5] != '\n'))return report (options, obj,FSCK_MSG_BAD_TIMEZONE ,"invalid author/committer line - bad time zone" ); - p +=6 ;return 0 ; }
ref-filter.c +0 -4
@@ -1634,10 +1634,6 @@ static int match_name_as_path(const struct ref_filter *filter, const char *refna {const char **pattern = filter->name_patterns;int namelen =strlen (refname); -unsigned flags =WM_PATHNAME ; - -if (filter->ignore_case) - flags |=WM_CASEFOLD ;for (; *pattern; pattern++) {const char *p = *pattern;
t/helper/test-lazy-init-name-hash.c +1 -1
@@ -209,7 +209,7 @@ int cmd_main(int argc, const char **argv) prefix =setup_git_directory (); - argc =parse_options (argc, argv, prefix, options, usage,0 ); +parse_options (argc, argv, prefix, options, usage,0 );/* * istate->dir_hash is only created when ignore_case is set.
wrapper.c +1 -1
@@ -485,7 +485,7 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode) template[2 ] = letters[v % num_letters]; v /= num_letters; template[3 ] = letters[v % num_letters]; v /= num_letters; template[4 ] = letters[v % num_letters]; v /= num_letters; - template[5 ] = letters[v % num_letters]; v /= num_letters; + template[5 ] = letters[v % num_letters]; fd =open (pattern,O_CREAT |O_EXCL |O_RDWR , mode);if (fd >=0 )
Signature · 1 line
2.12.3
Quoted 1 line · Дилян Палаузов
Signed-off-by Дилян Палаузов <[email protected]>
I assume this is just going through the results of clang's static analyzer and quieting it. I think most of these are not the right fix, though, as I discussed in
http://public-inbox.org/git/[email protected]/
For instance:
archive.c int write_archive(int argc, const char **argv, const char *prefix, · line 509
Quoted 13 lines
archive.c +1
-1@@ -503,7 +503,7 @@ int write_archive(int argc, const char **argv, const char *prefix,init_tar_archiver ();init_zip_archiver (); - argc =parse_archive_args (argc, argv, &ar, &args, name_hint, remote); +parse_archive_args (argc, argv, &ar, &args, name_hint, remote);if (!startup_info->have_repository) {/* * We know this will die() with an error, so we could just
It's true that nobody accesses argc after this, so the assignment is dead. But if we _don't_ assign to argc, we're leaving a maintenance trap for somebody who later does want to access it. Its value must match that what is in argv, and after your patch that invariant no longer holds.
Ditto for all of the argc hunks in this patch.
builtin/merge.c static int merge_trivial(struct commit *head, struct commit_list *remoteheads) · line 801
Quoted 13 lines
builtin/merge.c +1
-1@@ -795,7 +795,7 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)write_tree_trivial (&result_tree);printf (_ ("Wonderful.\n" )); pptr =commit_list_append (head, pptr); - pptr =commit_list_append (remoteheads->item, pptr); +commit_list_append (remoteheads->item, pptr);prepare_to_commit (remoteheads);if (commit_tree (merge_msg.buf, merge_msg.len, result_tree.hash, parents, result_commit.hash,NULL , sign_commit))
This one is similar. The return value of the append function updates the tail pointer. Nobody appends to the list, so we never look at the tail pointer again. But it has violated the tail-pointer invariant, and is setting a trap for somebody who tries to append to the list later.
builtin/notes.c int cmd_notes(int argc, const char **argv, const char *prefix) · line 1021
Quoted 13 lines
builtin/notes.c +1
-1@@ -1015,7 +1015,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)else if (!strcmp (argv[0 ],"get-ref" )) result =get_ref (argc, argv, prefix);else { - result =error (_ ("unknown subcommand: %s" ), argv[0 ]); +error (_ ("unknown subcommand: %s" ), argv[0 ]);usage_with_options (git_notes_usage, options); }
This one actually seems reasonable (usage_with_options exits, so we don't need to bother setting result).
builtin/receive-pack.c static const char *check_nonce(const char *buf, size_t len) · line 504
Quoted 13 lines
builtin/receive-pack.c +1
-1@@ -498,7 +498,7 @@ static const char *check_nonce(const char *buf, size_t len)char *nonce =find_header (buf, len,"nonce" );timestamp_t stamp, ostamp;char *bohmac, *expect =NULL ; -const char *retval =NONCE_BAD ; +const char *retval;if (!nonce) { retval =NONCE_MISSING ;
I have mixed feeling on this one. It's true that the NONCE_BAD value is never used. But it's a defensive programming measure to set the default in case we add code paths that do not set retval. If we could trust the compiler to tell us when the uninitialized value was used, that would let us avoid that situation. But the maybe-uninitialized warnings have historically been one of the least trustworthy warnings we've seen (most of the compiler-warning workarounds we've done have been for that).
fsck.c static int fsck_ident(const char **ident, struct object *obj, struct fsck_option · line 707
Quoted 11 lines
fsck.c +0
-1@@ -703,7 +703,6 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option !isdigit(p[4]) || (p[5] != '\n'))return report (options, obj,FSCK_MSG_BAD_TIMEZONE ,"invalid author/committer line - bad time zone" ); - p +=6 ;return 0 ; }
Another "invariant" one. Anybody adding more fsck checks would be surprised when "p" is not updated past the last check.
Quoted 5 lines
ref-filter.c +0
-0
ref-filter.c static int match_name_as_path(const struct ref_filter *filter, const char *refna · line 1639
Quoted 10 lines
ref-filter.c +0
-4@@ -1634,10 +1634,6 @@ static int match_name_as_path(const struct ref_filter *filter, const char *refna {const char **pattern = filter->name_patterns;int namelen =strlen (refname); -unsigned flags =WM_PATHNAME ; - -if (filter->ignore_case) - flags |=WM_CASEFOLD ;for (; *pattern; pattern++) {const char *p = *pattern;
I think this one is a real bug, but your fix is going in the wrong direction. Those lines were added by 3bb16a8bf (tag, branch,
for-each-ref: add --ignore-case for sorting and filtering, 2016-12-04), and it was probably a mistake that it did not update the call to wildmatch(). IOW, the fix is probably:
ref-filter.c +1 -1
@@ -1533,7 +1533,7 @@ static int match_name_as_path(const struct ref_filter *filter, const char *refna refname[plen] == '/' || p[plen-1] == '/'))return 1 ; -if (!wildmatch (p, refname,WM_PATHNAME ,NULL )) +if (!wildmatch (p, refname, flags,NULL ))return 1 ; }return 0 ;
-Peff