From 236788e7834799d57fb0854266f7a7f47bc57379 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 4 Apr 2022 22:35:54 -0500 Subject: [PATCH] Bugfix: The f_capability should accept f_string_constant_t rather than f_string_static_t. The name.string is incorrect and should be name->string. Once I fixed this, I noticed a compiler warning about losing the "const" frrom the return value of cap_mode_name(). Use f_string_constant_t rather than f_string_static_t. --- level_0/f_capability/c/capability.c | 8 +++----- level_0/f_capability/c/capability.h | 4 ++-- level_0/f_capability/tests/unit/c/test-capability-mode_get_name.c | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/level_0/f_capability/c/capability.c b/level_0/f_capability/c/capability.c index 68d7565..2f50e6b 100644 --- a/level_0/f_capability/c/capability.c +++ b/level_0/f_capability/c/capability.c @@ -210,7 +210,7 @@ extern "C" { #endif // _di_f_capability_mode_get_ #ifndef _di_f_capability_mode_get_name_ - f_status_t f_capability_mode_get_name(const f_capability_mode_t mode, f_string_static_t * const name) { + f_status_t f_capability_mode_get_name(const f_capability_mode_t mode, f_string_constant_t * const name) { #ifndef _di_level_0_parameter_checking_ if (!name) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -800,15 +800,13 @@ extern "C" { #endif // _di_f_capability_mode_get_ #ifndef _di_f_capability_mode_get_name_ - f_status_t f_capability_mode_get_name(const f_capability_mode_t mode, f_string_static_t * const name) { + f_status_t f_capability_mode_get_name(const f_capability_mode_t mode, f_string_constant_t * const name) { #ifndef _di_level_0_parameter_checking_ if (!mode) return F_status_set_error(F_parameter); if (!name) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - name.string = cap_mode_name(mode); - name.used = strnlen(name.string, F_string_t_size_d); - name.size = 0; + *name = cap_mode_name(mode); return F_none; } diff --git a/level_0/f_capability/c/capability.h b/level_0/f_capability/c/capability.h index d9ce645..d456c10 100644 --- a/level_0/f_capability/c/capability.h +++ b/level_0/f_capability/c/capability.h @@ -588,7 +588,7 @@ extern "C" { * The capability mode. * @param name * The name of the mode. - * This is NULL terminated after the name.used. + * This is a NULL terminated string. * * @return * F_none on success. @@ -600,7 +600,7 @@ extern "C" { * @see cap_get_mode() */ #ifndef _di_f_capability_mode_get_name_ - extern f_status_t f_capability_mode_get_name(const f_capability_mode_t mode, f_string_static_t * const name); + extern f_status_t f_capability_mode_get_name(const f_capability_mode_t mode, f_string_constant_t * const name); #endif // _di_f_capability_mode_get_name_ /** diff --git a/level_0/f_capability/tests/unit/c/test-capability-mode_get_name.c b/level_0/f_capability/tests/unit/c/test-capability-mode_get_name.c index a9d1443..3e6f8f6 100644 --- a/level_0/f_capability/tests/unit/c/test-capability-mode_get_name.c +++ b/level_0/f_capability/tests/unit/c/test-capability-mode_get_name.c @@ -21,7 +21,7 @@ extern "C" { void test__f_capability_mode_get_name__works(void **state) { const f_capability_mode_t mode = f_capability_mode_t_initialize; - f_string_static_t name = f_string_static_t_initialize; + f_string_constant_t name = f_string_constant_t_initialize; #if defined(_di_libcap_) || defined(_libcap_legacy_only_) printf("[ WARN ] f_capability_mode_get_name() is not implemented and cannot be fully tested.\n"); -- 1.8.3.1