Skip to content

Commit f22838a

Browse files
committed
Merge branch 'jk/misc-unused-fixes'
Assorted fixes for bugs found while auditing -Wunused-parameter warnings. * jk/misc-unused-fixes: approxidate: fix NULL dereference in date_time() pathspec: handle non-terminated strings with :(attr) approxidate: handle pending number for "specials" rev-list: handle flags for --indexed-objects
2 parents e146cc9 + aa097b8 commit f22838a

File tree

5 files changed

+59
-34
lines changed

5 files changed

+59
-34
lines changed

date.c

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -887,37 +887,69 @@ static time_t update_tm(struct tm *tm, struct tm *now, time_t sec)
887887
return n;
888888
}
889889

890+
/*
891+
* Do we have a pending number at the end, or when
892+
* we see a new one? Let's assume it's a month day,
893+
* as in "Dec 6, 1992"
894+
*/
895+
static void pending_number(struct tm *tm, int *num)
896+
{
897+
int number = *num;
898+
899+
if (number) {
900+
*num = 0;
901+
if (tm->tm_mday < 0 && number < 32)
902+
tm->tm_mday = number;
903+
else if (tm->tm_mon < 0 && number < 13)
904+
tm->tm_mon = number-1;
905+
else if (tm->tm_year < 0) {
906+
if (number > 1969 && number < 2100)
907+
tm->tm_year = number - 1900;
908+
else if (number > 69 && number < 100)
909+
tm->tm_year = number;
910+
else if (number < 38)
911+
tm->tm_year = 100 + number;
912+
/* We screw up for number = 00 ? */
913+
}
914+
}
915+
}
916+
890917
static void date_now(struct tm *tm, struct tm *now, int *num)
891918
{
919+
*num = 0;
892920
update_tm(tm, now, 0);
893921
}
894922

895923
static void date_yesterday(struct tm *tm, struct tm *now, int *num)
896924
{
925+
*num = 0;
897926
update_tm(tm, now, 24*60*60);
898927
}
899928

900929
static void date_time(struct tm *tm, struct tm *now, int hour)
901930
{
902931
if (tm->tm_hour < hour)
903-
date_yesterday(tm, now, NULL);
932+
update_tm(tm, now, 24*60*60);
904933
tm->tm_hour = hour;
905934
tm->tm_min = 0;
906935
tm->tm_sec = 0;
907936
}
908937

909938
static void date_midnight(struct tm *tm, struct tm *now, int *num)
910939
{
940+
pending_number(tm, num);
911941
date_time(tm, now, 0);
912942
}
913943

914944
static void date_noon(struct tm *tm, struct tm *now, int *num)
915945
{
946+
pending_number(tm, num);
916947
date_time(tm, now, 12);
917948
}
918949

919950
static void date_tea(struct tm *tm, struct tm *now, int *num)
920951
{
952+
pending_number(tm, num);
921953
date_time(tm, now, 17);
922954
}
923955

@@ -953,6 +985,7 @@ static void date_never(struct tm *tm, struct tm *now, int *num)
953985
{
954986
time_t n = 0;
955987
localtime_r(&n, tm);
988+
*num = 0;
956989
}
957990

958991
static const struct special {
@@ -1110,33 +1143,6 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num,
11101143
return end;
11111144
}
11121145

1113-
/*
1114-
* Do we have a pending number at the end, or when
1115-
* we see a new one? Let's assume it's a month day,
1116-
* as in "Dec 6, 1992"
1117-
*/
1118-
static void pending_number(struct tm *tm, int *num)
1119-
{
1120-
int number = *num;
1121-
1122-
if (number) {
1123-
*num = 0;
1124-
if (tm->tm_mday < 0 && number < 32)
1125-
tm->tm_mday = number;
1126-
else if (tm->tm_mon < 0 && number < 13)
1127-
tm->tm_mon = number-1;
1128-
else if (tm->tm_year < 0) {
1129-
if (number > 1969 && number < 2100)
1130-
tm->tm_year = number - 1900;
1131-
else if (number > 69 && number < 100)
1132-
tm->tm_year = number;
1133-
else if (number < 38)
1134-
tm->tm_year = 100 + number;
1135-
/* We screw up for number = 00 ? */
1136-
}
1137-
}
1138-
}
1139-
11401146
static timestamp_t approxidate_str(const char *date,
11411147
const struct timeval *tv,
11421148
int *error_ret)

dir.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,15 @@ static int match_attrs(const struct index_state *istate,
281281
const struct pathspec_item *item)
282282
{
283283
int i;
284+
char *to_free = NULL;
285+
286+
if (name[namelen])
287+
name = to_free = xmemdupz(name, namelen);
284288

285289
git_check_attr(istate, name, item->attr_check);
290+
291+
free(to_free);
292+
286293
for (i = 0; i < item->attr_match_nr; i++) {
287294
const char *value;
288295
int matched;

revision.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,28 +1327,30 @@ void add_reflogs_to_pending(struct rev_info *revs, unsigned flags)
13271327
}
13281328

13291329
static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
1330-
struct strbuf *path)
1330+
struct strbuf *path, unsigned int flags)
13311331
{
13321332
size_t baselen = path->len;
13331333
int i;
13341334

13351335
if (it->entry_count >= 0) {
13361336
struct tree *tree = lookup_tree(revs->repo, &it->oid);
1337+
tree->object.flags |= flags;
13371338
add_pending_object_with_path(revs, &tree->object, "",
13381339
040000, path->buf);
13391340
}
13401341

13411342
for (i = 0; i < it->subtree_nr; i++) {
13421343
struct cache_tree_sub *sub = it->down[i];
13431344
strbuf_addf(path, "%s%s", baselen ? "/" : "", sub->name);
1344-
add_cache_tree(sub->cache_tree, revs, path);
1345+
add_cache_tree(sub->cache_tree, revs, path, flags);
13451346
strbuf_setlen(path, baselen);
13461347
}
13471348

13481349
}
13491350

13501351
static void do_add_index_objects_to_pending(struct rev_info *revs,
1351-
struct index_state *istate)
1352+
struct index_state *istate,
1353+
unsigned int flags)
13521354
{
13531355
int i;
13541356

@@ -1362,13 +1364,14 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
13621364
blob = lookup_blob(revs->repo, &ce->oid);
13631365
if (!blob)
13641366
die("unable to add index blob to traversal");
1367+
blob->object.flags |= flags;
13651368
add_pending_object_with_path(revs, &blob->object, "",
13661369
ce->ce_mode, ce->name);
13671370
}
13681371

13691372
if (istate->cache_tree) {
13701373
struct strbuf path = STRBUF_INIT;
1371-
add_cache_tree(istate->cache_tree, revs, &path);
1374+
add_cache_tree(istate->cache_tree, revs, &path, flags);
13721375
strbuf_release(&path);
13731376
}
13741377
}
@@ -1378,7 +1381,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
13781381
struct worktree **worktrees, **p;
13791382

13801383
read_index(revs->repo->index);
1381-
do_add_index_objects_to_pending(revs, revs->repo->index);
1384+
do_add_index_objects_to_pending(revs, revs->repo->index, flags);
13821385

13831386
if (revs->single_worktree)
13841387
return;
@@ -1394,7 +1397,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
13941397
if (read_index_from(&istate,
13951398
worktree_git_path(wt, "index"),
13961399
get_worktree_git_dir(wt)) > 0)
1397-
do_add_index_objects_to_pending(revs, &istate);
1400+
do_add_index_objects_to_pending(revs, &istate, flags);
13981401
discard_index(&istate);
13991402
}
14001403
free_worktrees(worktrees);

t/t0006-date.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ check_approxidate '3:00' '2009-08-30 03:00:00'
113113
check_approxidate '15:00' '2009-08-30 15:00:00'
114114
check_approxidate 'noon today' '2009-08-30 12:00:00'
115115
check_approxidate 'noon yesterday' '2009-08-29 12:00:00'
116+
check_approxidate 'January 5th noon pm' '2009-01-05 12:00:00'
117+
check_approxidate '10am noon' '2009-08-29 12:00:00'
116118

117119
check_approxidate 'last tuesday' '2009-08-25 19:20:00'
118120
check_approxidate 'July 5th' '2009-07-05 19:20:00'

t/t6000-rev-list-misc.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,18 @@ test_expect_success 'rev-list can show index objects' '
9090
9200b628cf9dc883a85a7abc8d6e6730baee589c two
9191
EOF
9292
echo only-in-index >only-in-index &&
93+
test_when_finished "git reset --hard" &&
9394
git add only-in-index &&
9495
git rev-list --objects --indexed-objects >actual &&
9596
test_cmp expect actual
9697
'
9798

99+
test_expect_success 'rev-list can negate index objects' '
100+
git rev-parse HEAD >expect &&
101+
git rev-list -1 --objects HEAD --not --indexed-objects >actual &&
102+
test_cmp expect actual
103+
'
104+
98105
test_expect_success '--bisect and --first-parent can not be combined' '
99106
test_must_fail git rev-list --bisect --first-parent HEAD
100107
'

0 commit comments

Comments
 (0)