Skip to content

Commit dd3bfe4

Browse files
committed
Merge branch 'ma/ts-cleanups' into maint
Assorted bugfixes and clean-ups. * ma/ts-cleanups: ThreadSanitizer: add suppressions strbuf_setlen: don't write to strbuf_slopbuf pack-objects: take lock before accessing `remaining` convert: always initialize attr_action in convert_attrs
2 parents a37b73e + 6cdf8a7 commit dd3bfe4

File tree

6 files changed

+37
-3
lines changed

6 files changed

+37
-3
lines changed

.tsan-suppressions

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Suppressions for ThreadSanitizer (tsan).
2+
#
3+
# This file is used by setting the environment variable TSAN_OPTIONS to, e.g.,
4+
# "suppressions=$(pwd)/.tsan-suppressions". Observe that relative paths such as
5+
# ".tsan-suppressions" might not work.
6+
7+
# A static variable is written to racily, but we always write the same value, so
8+
# in practice it (hopefully!) doesn't matter.
9+
race:^want_color$
10+
race:^transfer_debug$

builtin/pack-objects.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,10 @@ static void *threaded_find_deltas(void *arg)
21702170
{
21712171
struct thread_params *me = arg;
21722172

2173+
progress_lock();
21732174
while (me->remaining) {
2175+
progress_unlock();
2176+
21742177
find_deltas(me->list, &me->remaining,
21752178
me->window, me->depth, me->processed);
21762179

@@ -2192,7 +2195,10 @@ static void *threaded_find_deltas(void *arg)
21922195
pthread_cond_wait(&me->cond, &me->mutex);
21932196
me->data_ready = 0;
21942197
pthread_mutex_unlock(&me->mutex);
2198+
2199+
progress_lock();
21952200
}
2201+
progress_unlock();
21962202
/* leave ->working 1 so that this doesn't get more work assigned */
21972203
return NULL;
21982204
}

color.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,13 @@ static int check_auto_color(void)
338338

339339
int want_color(int var)
340340
{
341+
/*
342+
* NEEDSWORK: This function is sometimes used from multiple threads, and
343+
* we end up using want_auto racily. That "should not matter" since
344+
* we always write the same value, but it's still wrong. This function
345+
* is listed in .tsan-suppressions for the time being.
346+
*/
347+
341348
static int want_auto = -1;
342349

343350
if (var < 0)

convert.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,6 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
10411041
ca->crlf_action = git_path_check_crlf(ccheck + 4);
10421042
if (ca->crlf_action == CRLF_UNDEFINED)
10431043
ca->crlf_action = git_path_check_crlf(ccheck + 0);
1044-
ca->attr_action = ca->crlf_action;
10451044
ca->ident = git_path_check_ident(ccheck + 1);
10461045
ca->drv = git_path_check_convert(ccheck + 2);
10471046
if (ca->crlf_action != CRLF_BINARY) {
@@ -1055,12 +1054,14 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
10551054
else if (eol_attr == EOL_CRLF)
10561055
ca->crlf_action = CRLF_TEXT_CRLF;
10571056
}
1058-
ca->attr_action = ca->crlf_action;
10591057
} else {
10601058
ca->drv = NULL;
10611059
ca->crlf_action = CRLF_UNDEFINED;
10621060
ca->ident = 0;
10631061
}
1062+
1063+
/* Save attr and make a decision for action */
1064+
ca->attr_action = ca->crlf_action;
10641065
if (ca->crlf_action == CRLF_TEXT)
10651066
ca->crlf_action = text_eol_is_crlf() ? CRLF_TEXT_CRLF : CRLF_TEXT_INPUT;
10661067
if (ca->crlf_action == CRLF_UNDEFINED && auto_crlf == AUTO_CRLF_FALSE)

strbuf.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len)
154154
if (len > (sb->alloc ? sb->alloc - 1 : 0))
155155
die("BUG: strbuf_setlen() beyond buffer");
156156
sb->len = len;
157-
sb->buf[len] = '\0';
157+
if (sb->buf != strbuf_slopbuf)
158+
sb->buf[len] = '\0';
159+
else
160+
assert(!strbuf_slopbuf[0]);
158161
}
159162

160163
/**

transport-helper.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,13 @@ int transport_helper_init(struct transport *transport, const char *name)
11171117
__attribute__((format (printf, 1, 2)))
11181118
static void transfer_debug(const char *fmt, ...)
11191119
{
1120+
/*
1121+
* NEEDSWORK: This function is sometimes used from multiple threads, and
1122+
* we end up using debug_enabled racily. That "should not matter" since
1123+
* we always write the same value, but it's still wrong. This function
1124+
* is listed in .tsan-suppressions for the time being.
1125+
*/
1126+
11201127
va_list args;
11211128
char msgbuf[PBUFFERSIZE];
11221129
static int debug_enabled = -1;

0 commit comments

Comments
 (0)