Skip to content

Warning fix#48

Merged
Moe-hacker merged 8 commits intoRuriOSS:mainfrom
dabao1955:k2v
Mar 15, 2026
Merged

Warning fix#48
Moe-hacker merged 8 commits intoRuriOSS:mainfrom
dabao1955:k2v

Conversation

@dabao1955
Copy link
Contributor

@dabao1955 dabao1955 commented Jan 27, 2026

✅ Normal merge
✅ Rebase merge
❌ Squash merge

@dabao1955 dabao1955 changed the title Replace GCC statement expression with standard C function Warning fix Jan 27, 2026
The `k2v_add_config` macro previously used a GCC-specific braced-group
expression (`({ ... })`), which triggers `-Wpedantic` warnings and is not
ISO C compliant. This change replaces it with a standard C helper function
`k2v__append_and_free`, defined in `k2v.c`, and updates the macro to call
this function.

This eliminates all `-Wpedantic` warnings related to `k2v_add_config` while
preserving the original API and behavior. The helper function handles
string concatenation, memory allocation, and cleanup in a portable way.

Also fixes a linking issue by removing the incorrect `static` declaration
from the header and ensuring the function has external linkage.
The `k2v_open_file` function previously compared `ssize_t len` (from `read`)
with `size_t strlen(ret)`, triggering a `-Wsign-compare` warning. More
importantly, the check `if (len != strlen(ret))` was logically flawed: it
would fire whenever the file contained embedded null bytes — which is
expected behavior for `strlen`, but not necessarily an error for config
files.

Since the function already explicitly null-terminates the buffer with
`ret[len] = '\0'`, the string is always properly terminated. The warning
message about "\0 is not the end of file" was misleading and unnecessary.

This change:
- Removes the problematic comparison
- Simplifies error handling
- Reduces allocated buffer size from `bufsize + 2` to `bufsize + 1`
- Adds missing check for `read()` failure

The function now safely returns a null-terminated string without spurious
warnings or undefined comparisons.
@dabao1955 dabao1955 force-pushed the k2v branch 6 times, most recently from 1a65761 to 1a0d312 Compare January 28, 2026 06:53
dabao1955 and others added 6 commits March 13, 2026 20:41
The `errno_map` array in `ruri_resolve_seccomp_errno` previously stored errno
values as `int`, causing a `-Wsign-conversion` warning when passed to
`SCMP_ACT_ERRNO()`, which expects an unsigned value.

Since all standard errno constants (e.g., EPERM, EACCES) are positive and
libseccomp requires errno codes in the range [1, 4095], changing the field
type to `unsigned int` is both safe and semantically correct.

This eliminates the compiler warning without altering behavior.
- Replace non-standard escape sequence `\e` with `\033` for ISO C compliance
- Change `int n` to `ssize_t n` when capturing return value of `read()`
- Use `size_t` for loop index to match `strlen()` return type

These changes eliminate -Wpedantic, -Wconversion, and -Wsign-compare
warnings while improving robustness and portability.
@Moe-hacker Moe-hacker merged commit e1aaddf into RuriOSS:main Mar 15, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants