fix: bound compression worker threads
CI / lint (pull_request) Successful in 11s
CI / sanitizers (address) (pull_request) Successful in 38s
CI / sanitizers (undefined) (pull_request) Successful in 37s
CI / fuzz-build (pull_request) Successful in 15s
CI / coverage (pull_request) Successful in 32s
CI / build-and-test (pull_request) Successful in 1m15s
CI / valgrind (pull_request) Successful in 34s

This commit is contained in:
2026-09-03 22:22:04 +02:00
parent f443b2986d
commit ec02ee6dde
5 changed files with 36 additions and 11 deletions
+15 -4
View File
@@ -1,5 +1,6 @@
#include "client_send.h"
#include "client_validation.h"
#include "compression.h"
#include "config.h"
#include "delta.h"
#include "log.h"
@@ -77,6 +78,17 @@ static int set_positive_int_option(int* dest, const char* value, const char* opt
return 0;
}
static int set_compression_threads_option(int* dest, const char* value) {
if (set_positive_int_option(dest, value, "--compress-threads") != 0)
return -1;
if (*dest > COMPRESSION_MAX_THREADS) {
log_message(LOG_LEVEL_ERROR, "--compress-threads must be between 1 and %d",
COMPRESSION_MAX_THREADS);
return -1;
}
return 0;
}
/* Parse a string as a non-negative integer into *dest. Returns true on success, false on error. */
static int set_nonneg_int_option(int* dest, const char* value, const char* option_name) {
if (!parse_nonneg_int(value, dest)) {
@@ -213,8 +225,8 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
for (int i = 1; i < argc; i++) {
const char* threads_prefix = "--compress-threads=";
if (strncmp(argv[i], threads_prefix, strlen(threads_prefix)) == 0) {
if (set_positive_int_option(&config->compression_threads, argv[i] + strlen(threads_prefix),
"--compress-threads") != 0)
if (set_compression_threads_option(&config->compression_threads,
argv[i] + strlen(threads_prefix)) != 0)
return -1;
continue;
}
@@ -369,8 +381,7 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
return -1;
}
} else if (opt_is(argv[i], "--compress-threads", NULL) && i + 1 < argc) {
if (set_positive_int_option(&config->compression_threads, argv[++i], "--compress-threads") !=
0)
if (set_compression_threads_option(&config->compression_threads, argv[++i]) != 0)
return -1;
} else if (argv[i][0] == '-') {
fprintf(stderr, "Unknown option: %s\n", argv[i]);