diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-10-14 00:33:39 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-10-14 00:33:39 +0200 |
commit | 613f53b44279c44a8f53783d2dc4410584133431 (patch) | |
tree | 1f6bb8c959f523682294824681e9131ece27adfd /src | |
parent | 8664aa16e2df5d94a594785661283a39340db2fd (diff) | |
download | blogc-613f53b44279c44a8f53783d2dc4410584133431.tar.gz blogc-613f53b44279c44a8f53783d2dc4410584133431.tar.bz2 blogc-613f53b44279c44a8f53783d2dc4410584133431.zip |
runserver: blogc/loader: improve strto*l handling
Diffstat (limited to 'src')
-rw-r--r-- | src/blogc-runserver/httpd.c | 5 | ||||
-rw-r--r-- | src/blogc-runserver/main.c | 18 | ||||
-rw-r--r-- | src/blogc/loader.c | 18 |
3 files changed, 34 insertions, 7 deletions
diff --git a/src/blogc-runserver/httpd.c b/src/blogc-runserver/httpd.c index 195bad0..1312ec9 100644 --- a/src/blogc-runserver/httpd.c +++ b/src/blogc-runserver/httpd.c @@ -212,6 +212,11 @@ int br_httpd_run(const char *host, unsigned short port, const char *docroot, size_t max_threads) { + if (port == 0) { + fprintf(stderr, "Invalid port: 0\n"); + return 1; + } + thread_data_t threads[max_threads]; for (size_t i = 0; i < max_threads; i++) threads[i].initialized = false; diff --git a/src/blogc-runserver/main.c b/src/blogc-runserver/main.c index 4563a66..0b8d0fe 100644 --- a/src/blogc-runserver/main.c +++ b/src/blogc-runserver/main.c @@ -54,6 +54,8 @@ main(int argc, char **argv) char *docroot = NULL; unsigned short port = 8080; size_t max_threads = 20; + char *ptr; + char *endptr; unsigned int args = 0; @@ -74,15 +76,23 @@ main(int argc, char **argv) break; case 'p': if (argv[i][2] != '\0') - port = strtoul(argv[i] + 2, NULL, 10); + ptr = argv[i] + 2; else - port = strtoul(argv[++i], NULL, 10); + ptr = argv[++i]; + port = strtoul(ptr, &endptr, 10); + if (*ptr != '\0' && *endptr != '\0') + fprintf(stderr, "blogc-runserver: warning: invalid value " + "for -p argument: %s. using %hu instead\n", ptr, port); break; case 'm': if (argv[i][2] != '\0') - max_threads = strtoul(argv[i] + 2, NULL, 10); + ptr = argv[i] + 2; else - max_threads = strtoul(argv[++i], NULL, 10); + ptr = argv[++i]; + max_threads = strtoul(argv[++i], NULL, 10); + if (*ptr != '\0' && *endptr != '\0') + fprintf(stderr, "blogc-runserver: warning: invalid value " + "for -m argument: %s. using %zu instead\n", ptr, max_threads); break; default: print_usage(); diff --git a/src/blogc/loader.c b/src/blogc/loader.c index bca0000..57db98f 100644 --- a/src/blogc/loader.c +++ b/src/blogc/loader.c @@ -9,6 +9,7 @@ #include <math.h> #include <stdbool.h> #include <stddef.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include "source-parser.h" @@ -105,11 +106,22 @@ blogc_source_parse_from_files(bc_trie_t *conf, bc_slist_t *l, bc_error_t **err) const char *filter_page = bc_trie_lookup(conf, "FILTER_PAGE"); const char *filter_per_page = bc_trie_lookup(conf, "FILTER_PER_PAGE"); - long page = strtol(filter_page != NULL ? filter_page : "", NULL, 10); + const char *ptr; + char *endptr; + + ptr = filter_page != NULL ? filter_page : ""; + long page = strtol(ptr, &endptr, 10); + if (*ptr != '\0' && *endptr != '\0') + fprintf(stderr, "warning: invalid value for 'FILTER_PAGE' variable: " + "%s. using %ld instead\n", ptr, page); if (page <= 0) page = 1; - long per_page = strtol(filter_per_page != NULL ? filter_per_page : "10", - NULL, 10); + + ptr = filter_per_page != NULL ? filter_per_page : "10"; + long per_page = strtol(ptr, &endptr, 10); + if (*ptr != '\0' && *endptr != '\0') + fprintf(stderr, "warning: invalid value for 'FILTER_PER_PAGE' variable: " + "%s. using %ld instead\n", ptr, per_page); if (per_page <= 0) per_page = 10; |