Skip to content

Commit 6cd006c

Browse files
committed
Code quality improvements
- Improve error messages - Enable -Wshadow - Removed the extra 1 byte workaround (I am not sure why this was needed in the first place.)
1 parent 614b9d8 commit 6cd006c

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ srcs = [
2323

2424
c_args = [
2525
'-Wstrict-prototypes',
26+
'-Wshadow',
2627
'-pthread',
2728
'-D_GNU_SOURCE',
2829
'-DVERSION="' + meson.project_version() + '"'

src/cache.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,15 +945,16 @@ cf->content_length: %ld, Data_size(fn): %ld.\n", fn, cf->content_length,
945945
void Cache_close(Cache *cf)
946946
{
947947
lprintf(cache_lock_debug,
948-
"thread %x: locking cf_lock;\n", pthread_self());
948+
"thread %x: locking cf_lock: %s\n", pthread_self(), cf->path);
949949
PTHREAD_MUTEX_LOCK(&cf_lock);
950950

951951
cf->cache_opened--;
952952

953953
if (cf->cache_opened > 0) {
954954

955955
lprintf(cache_lock_debug,
956-
"thread %x: unlocking cf_lock;\n", pthread_self());
956+
"thread %x: unlocking cf_lock: %s, cache_opened: %d\n",
957+
pthread_self(), cf->path, cf->cache_opened);
957958
PTHREAD_MUTEX_UNLOCK(&cf_lock);
958959
return;
959960
}
@@ -973,7 +974,8 @@ void Cache_close(Cache *cf)
973974
cf->link->cache_ptr = NULL;
974975

975976
lprintf(cache_lock_debug,
976-
"thread %x: unlocking cf_lock;\n", pthread_self());
977+
"thread %x: unlocking cf_lock, cache closed: %s\n", pthread_self(),
978+
cf->path);
977979
PTHREAD_MUTEX_UNLOCK(&cf_lock);
978980
Cache_free(cf);
979981
}

src/link.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,31 +1077,30 @@ long Link_download(Link *link, char *output_buf, size_t req_size, off_t offset)
10771077
header.curr_size = 0;
10781078
header.data = NULL;
10791079

1080-
if (offset + req_size > link->content_length) {
1080+
size_t request_end = offset + req_size;
1081+
if (request_end > link->content_length) {
10811082
lprintf(info,
1082-
"requested size larger than remaining size, req_size: %lu, recv: %ld, content-length: %ld\n",
1083-
req_size, recv, link->content_length);
1083+
"requested size larger than remaining size, request_end: \
1084+
%lu, content-length: %ld\n", request_end, link->content_length);
10841085
req_size = link->content_length - offset;
10851086
}
10861087

10871088
CURL *curl = Link_download_curl_setup(link, req_size, offset, &header, &ts);
10881089

10891090
transfer_blocking(curl);
10901091

1091-
curl_off_t recv = Link_download_cleanup(curl, &header);
1092+
curl_off_t recv_sz = Link_download_cleanup(curl, &header);
10921093

1093-
/* The extra 1 byte is probably for '\0' */
1094-
if (recv - 1 == (long int) req_size) {
1095-
recv--;
1096-
} else {
1094+
if (recv_sz != (long int) req_size)
1095+
{
10971096
lprintf(error, "req_size != recv, req_size: %lu, recv: %ld\n",
1098-
req_size, recv);
1097+
req_size, recv_sz);
10991098
}
11001099

1101-
memmove(output_buf, ts.data, recv);
1100+
memmove(output_buf, ts.data, recv_sz);
11021101
FREE(ts.data);
11031102

1104-
return recv;
1103+
return recv_sz;
11051104
}
11061105

11071106
long path_download(const char *path, char *output_buf, size_t req_size,

0 commit comments

Comments
 (0)