From c36a00929b4eb1709debfe1c793c21c31e03e556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Thu, 18 Feb 2016 16:39:14 +0100 Subject: [PATCH 1/5] Low: no magic constants + gethostname usage sanity --- lib/log_format.c | 7 ++++--- tests/check_log.c | 13 +++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/log_format.c b/lib/log_format.c index 6c29f0a95..82fa1eb03 100644 --- a/lib/log_format.c +++ b/lib/log_format.c @@ -272,10 +272,11 @@ qb_log_target_format_static(int32_t target, const char * format, break; case 'H': - if (gethostname(tmp_buf, 255) == 0) { - tmp_buf[254] = '\0'; + if (gethostname(tmp_buf, sizeof(tmp_buf)) == 0) { + tmp_buf[sizeof(tmp_buf) - 1] = '\0'; } else { - (void)strlcpy(tmp_buf, "localhost", 255); + (void)strlcpy(tmp_buf, "localhost", + sizeof(tmp_buf)); } p = tmp_buf; break; diff --git a/tests/check_log.c b/tests/check_log.c index d7ac70bc8..853862016 100644 --- a/tests/check_log.c +++ b/tests/check_log.c @@ -450,8 +450,10 @@ static const char *_test_tags_stringify(uint32_t tags) START_TEST(test_log_format) { int32_t t; - char cmp_str[256]; + /* following size/length related equation holds in the context of use: + strlen(cmp_str) = strlen(host_str) + X; X ~ 20 < sizeof(host_str) */ char host_str[256]; + char cmp_str[2 * sizeof(host_str)]; qb_log_init("test", LOG_USER, LOG_DEBUG); qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE); @@ -498,16 +500,19 @@ START_TEST(test_log_format) qb_log_tags_stringify_fn_set(NULL); - gethostname(host_str, 256); + gethostname(host_str, sizeof(host_str)); + host_str[sizeof(host_str) - 1] = '\0'; qb_log_format_set(t, "%P %H %N %b"); qb_log(LOG_INFO, "Angus"); - snprintf(cmp_str, 256, "%d %s test Angus", getpid(), host_str); + snprintf(cmp_str, sizeof(cmp_str), "%d %s test Angus", getpid(), + host_str); ck_assert_str_eq(test_buf, cmp_str); qb_log_format_set(t, "%3N %H %P %b"); qb_log(LOG_INFO, "Angus"); - snprintf(cmp_str, 256, "tes %s %d Angus", host_str, getpid()); + snprintf(cmp_str, sizeof(cmp_str), "tes %s %d Angus", host_str, + getpid()); ck_assert_str_eq(test_buf, cmp_str); } END_TEST From cabe021d47bd16431a3889471066c6fc3ef1e1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Thu, 18 Feb 2016 18:28:03 +0100 Subject: [PATCH 2/5] build: fix "dependant" typo --- docs/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Makefile.am b/docs/Makefile.am index 0c6eaa3d2..61ddc0f07 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -24,14 +24,14 @@ noinst_HEADERS = mainpage.h dist_man_MANS = man8/qb-blackbox.8 if HAVE_DOXYGEN inc_dir = $(top_srcdir)/include/qb -dependant_headers = $(wildcard $(inc_dir)/qb*.h) +dependent_headers = $(wildcard $(inc_dir)/qb*.h) dist_man_MANS += man3/qbipcc.h.3 man3/qbipcs.h.3 man3/qbatomic.h.3 \ man3/qbhdb.h.3 man3/qbipc_common.h.3 man3/qblist.h.3 \ man3/qbloop.h.3 man3/qbutil.h.3 man3/qbarray.h.3 \ man3/qblog.h.3 man3/qbmap.h.3 -$(dist_man_MANS): man.dox $(dependant_headers) +$(dist_man_MANS): man.dox $(dependent_headers) mkdir -p man3 doxygen man.dox From 0b04ed5e77bddd115ec86a6421f6171f19ed4250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Thu, 18 Feb 2016 18:32:08 +0100 Subject: [PATCH 3/5] build: grab "dependent_headers" from respective Makefile.am ...with "echo path/*.h" fallback (equivalent of wildcard function) if the new methods fails for some reason. --- docs/Makefile.am | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/Makefile.am b/docs/Makefile.am index 61ddc0f07..957a9317e 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -24,14 +24,19 @@ noinst_HEADERS = mainpage.h dist_man_MANS = man8/qb-blackbox.8 if HAVE_DOXYGEN inc_dir = $(top_srcdir)/include/qb -dependent_headers = $(wildcard $(inc_dir)/qb*.h) + +dependent_headers = $(subst $(inc_dir),,$(shell \ + printf 'include $(inc_dir)/Makefile.am\n\n%%.var:\n\t@echo $$($$*)' \ + | ${MAKE} --no-print-directory -f - inst_HEADERS.var \ + || echo $(inc_dir)/qb*.h)) + dist_man_MANS += man3/qbipcc.h.3 man3/qbipcs.h.3 man3/qbatomic.h.3 \ man3/qbhdb.h.3 man3/qbipc_common.h.3 man3/qblist.h.3 \ man3/qbloop.h.3 man3/qbutil.h.3 man3/qbarray.h.3 \ man3/qblog.h.3 man3/qbmap.h.3 -$(dist_man_MANS): man.dox $(dependent_headers) +$(dist_man_MANS): man.dox $(dependent_headers:%=$(inc_dir)/%) mkdir -p man3 doxygen man.dox From cf1588c6ecb113db922112837163fd3a9668cdfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Thu, 18 Feb 2016 18:56:54 +0100 Subject: [PATCH 4/5] build: header-based man pages: dependent_headers - blacklist IOW, make tracking of interfaces to document via man pages maintainable. --- docs/Makefile.am | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/Makefile.am b/docs/Makefile.am index 957a9317e..32c6d08f9 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -29,12 +29,11 @@ dependent_headers = $(subst $(inc_dir),,$(shell \ printf 'include $(inc_dir)/Makefile.am\n\n%%.var:\n\t@echo $$($$*)' \ | ${MAKE} --no-print-directory -f - inst_HEADERS.var \ || echo $(inc_dir)/qb*.h)) +dependent_headers_omit = qbconfig.h qbdefs.h qbrb.h -dist_man_MANS += man3/qbipcc.h.3 man3/qbipcs.h.3 man3/qbatomic.h.3 \ - man3/qbhdb.h.3 man3/qbipc_common.h.3 man3/qblist.h.3 \ - man3/qbloop.h.3 man3/qbutil.h.3 man3/qbarray.h.3 \ - man3/qblog.h.3 man3/qbmap.h.3 - +dist_man_MANS += $(patsubst %,man3/%.3,$(filter-out \ + $(dependent_headers_omit),$(dependent_headers) \ + )) $(dist_man_MANS): man.dox $(dependent_headers:%=$(inc_dir)/%) mkdir -p man3 From 792c34bf6b8b25af0e675e7e3d2d02dc1428715a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Thu, 18 Feb 2016 19:04:48 +0100 Subject: [PATCH 5/5] build: header-based man pages: include also qbdefs.h+qbrb.h No reason not to do that. Situation with qbconfig.h is a bit more complicated as this file gets generated from .in file and there is currently no reliable inter-dir/makefile (siblings) targets dependency tracking in place, AFAICT. --- docs/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Makefile.am b/docs/Makefile.am index 32c6d08f9..2ca1b0ab4 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -29,7 +29,7 @@ dependent_headers = $(subst $(inc_dir),,$(shell \ printf 'include $(inc_dir)/Makefile.am\n\n%%.var:\n\t@echo $$($$*)' \ | ${MAKE} --no-print-directory -f - inst_HEADERS.var \ || echo $(inc_dir)/qb*.h)) -dependent_headers_omit = qbconfig.h qbdefs.h qbrb.h +dependent_headers_omit = qbconfig.h dist_man_MANS += $(patsubst %,man3/%.3,$(filter-out \ $(dependent_headers_omit),$(dependent_headers) \