Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
revision: parse "git log -<count>" more carefully
author
Junio C Hamano
<gitster@pobox.com>
Fri, 6 Jun 2014 22:33:25 +0000
(15:33 -0700)
committer
Junio C Hamano
<gitster@pobox.com>
Mon, 9 Jun 2014 21:53:49 +0000
(14:53 -0700)
This mistyped command line simply ignores "master" and ends up
showing two commits from the current HEAD:
$ git log -2master
because we feed "2master" to atoi() without making sure that the
whole string is parsed as an integer.
Use the strtol_i() helper function instead.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
revision.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
7bbc4e8
)
diff --git
a/revision.c
b/revision.c
index 7afedc50fcdc1346a81ab3d95a557c85333c97b9..d5e2f1a257dfd508bd2a2d1f1fde6c49a03541f5 100644
(file)
--- a/
revision.c
+++ b/
revision.c
@@
-1612,8
+1612,10
@@
static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->skip_count = atoi(optarg);
return argcount;
} else if ((*arg == '-') && isdigit(arg[1])) {
revs->skip_count = atoi(optarg);
return argcount;
} else if ((*arg == '-') && isdigit(arg[1])) {
- /* accept -<digit>, like traditional "head" */
- revs->max_count = atoi(arg + 1);
+ /* accept -<digit>, like traditional "head" */
+ if (strtol_i(arg + 1, 10, &revs->max_count) < 0 ||
+ revs->max_count < 0)
+ die("'%s': not a non-negative integer", arg + 1);
revs->no_walk = 0;
} else if (!strcmp(arg, "-n")) {
if (argc <= 1)
revs->no_walk = 0;
} else if (!strcmp(arg, "-n")) {
if (argc <= 1)