typecast issue in dlt_user.c : strlen(DLT_USER_DEFAULT_ECU_ID)
- Dominant language
- C
- Stars
- 459
- Forks
- 340
- Avg merge
- 4d 21h
- Merged PRs (30d)
- 2
Description
Error message - build_libdlt/src/lib/dlt_user.c:848:26: error: conversion to ‘uint8_t {aka unsigned char}’ from ‘size_t {aka long unsigned int}’ may alter its value [-Werror=conversion]
dlt_user.ecuID2len = strlen(DLT_USER_DEFAULT_ECU_ID);
^~~~~~
compilation terminated due to -Wfatal-errors.
Proposed fix:
We tried removing the line causing the error, and the run went fine
changes in https://github.com/COVESA/dlt-daemon/pull/886
can you please go throught the PR and the issue, and suggest if the fix in our PR is the correct way to solve the issue, OR is there any other way for it?
we also thought to explicitly typecasting the variable before the error line, (we haven;t tested this) this also can be one possible fix -
```python
size_t ecu_len = strlen(DLT_USER_DEFAULT_ECU_ID);
if (ecu_len > UINT8_MAX) {
/* Choose your policy: clamp, log+fail, or return error */
ecu_len = UINT8_MAX;
}
dlt_set_id(dlt_user.ecuID, DLT_USER_DEFAULT_ECU_ID);
dlt_user.ecuID2len = (uint8_t)ecu_len;
dlt_set_id_v2(dlt_user.ecuID2, DLT_USER_DEFAULT_ECU_ID, dlt_user.ecuID2len);
dlt_set_id(dlt_user.appID, "");
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Inspect build_libdlt/src/lib/dlt_user.c around line 848 and review PR 886 first. Trace how ecuID2len is used, then build with the reported conversion warning enabled and verify that the warning is gone without changing the expected ECU ID behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100