Fix 32-bit time_t compile errors in DLTv2 timestamp code#856
Open
xl4hub wants to merge 1 commit into
Open
Conversation
9920709 to
11ec58a
Compare
minminlittleshrimp
requested changes
Apr 23, 2026
On platforms where time_t is 32-bit (e.g. armv7/musl, glibc arm with default _FILE_OFFSET_BITS), several DLTv2 timestamp call sites trigger -Werror=shift-count-overflow, -Werror=sign-conversion, or -Werror=sign-compare, preventing compilation. Fixes: - ts.tv_sec >> 32 (9 sites in dlt-daemon.c, dlt_daemon_client.c, dlt_client.c, dlt_user.c, dlt_common.c): cast to uint64_t before shifting. On 32-bit time_t the shift is UB; on 64-bit it is a no-op. The top byte of the 40-bit seconds field is now correctly zero on 32-bit platforms instead of carrying a stray duplicate of the low byte (caused by ARM's 5-bit shift-count mask). - time_t tt = msg->storageheader->seconds (dlt_common.c:1084): explicit (time_t) cast to silence sign-conversion when time_t is signed 32-bit. - st.st_size > UINT_MAX (dlt_user.c:5620): cast st.st_size to uintmax_t for the comparison, avoiding the signed/unsigned mismatch between off_t and unsigned int. Signed-off-by: john crosbie <john@excelfore.com>
11ec58a to
98d78ee
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On platforms where
time_tis 32-bit (e.g. armv7 Linux with default_FILE_OFFSET_BITS), several DLTv2 timestamp call sites trigger-Werror=shift-count-overflow,-Werror=sign-conversion, or-Werror=sign-compare, preventing compilation with the-Werrorflags the project sets in its top-levelCMakeLists.txt.Fixes
ts.tv_sec >> 32(9 sites acrossdlt-daemon.c,dlt_daemon_client.c,dlt_client.c,dlt_user.c,dlt_common.c) — castts.tv_sectouint64_tbefore the shift. On 32-bittime_tthe shift was undefined behavior; on ARM it silently wrapped to>> 0due to the 5-bit shift-count mask, which meantseconds[0]in the 40-bit DLTv2 timestamp carried a duplicate of the low byte instead of the expected 0. After the cast the top byte is correctly 0 on 32-bit platforms. No behavior change on 64-bit platforms.time_t tt = msg->storageheader->seconds(dlt_common.c:1084) — explicit(time_t)cast to silence-Wsign-conversionwhentime_tis signed 32-bit andstorageheader->secondsisuint32_t.st.st_size > UINT_MAX(dlt_user.c:5620) — castst.st_sizetouintmax_tfor the comparison to avoid-Wsign-comparebetweenoff_t(signed long) andunsigned int. The precedingst.st_size < 0check still guards the cast.Test plan
dltanddlt-daemonfor armv7 Linux (glibc, 32-bittime_t) with-Werror -Wfatal-errors -Wconversion -Wshadow -Wundef -Wcast-qual— clean build and install.time_t).Supersedes #855 (closed to correct commit authorship).
Author: john@excelfore.com