Skip to content

[Coverity CID: 368811] Unintended sign extension in drivers/sensor/tsic_xx6/tsic_xx6.c #74776

@zephyrbot

Description

@zephyrbot

Static code scan issues found in file:

https://github.com/zephyrproject-rtos/zephyr/tree/dcf42917c550714d2457947538b9e29d083e872e/drivers/sensor/tsic_xx6/tsic_xx6.c#L164

Category: Integer handling issues
Function: tsic_xx6_get_value
Component: Drivers
CID: 368811

Details:

tmp = data_bits * (config->higher_temperature_limit - config->lower_temperature_limit);

158     static void tsic_xx6_get_value(const struct tsic_xx6_config *config, struct tsic_xx6_data *data,
159                             uint16_t data_bits)
160     {
161      int64_t tmp;
162    
163      /* Apply the datasheet formula scaled to micro celcius */
>>>     CID 368811:  Integer handling issues  (SIGN_EXTENSION)
>>>     Suspicious implicit sign extension: "data_bits" with type "uint16_t" (16 bits, unsigned) is promoted in "data_bits * (config->higher_temperature_limit - config->lower_temperature_limit)" to type "int" (32 bits, signed), then sign-extended to type "long long" (64 bits, signed).  If "data_bits * (config->higher_temperature_limit - config->lower_temperature_limit)" is greater than 0x7FFFFFFF, the upper bits of the result will all be 1.
164      tmp = data_bits * (config->higher_temperature_limit - config->lower_temperature_limit);
165      tmp = tmp * 1000000 / (BIT(config->data_bits) - 1);
166      tmp += (int64_t)config->lower_temperature_limit * 1000000;
167    
168      data->val.val1 = tmp / 1000000;
169      data->val.val2 = tmp % 1000000;

For more information about the violation, check the Coverity Reference. (CWE-194)

Please fix or provide comments in coverity using the link:

https://scan9.scan.coverity.com/#/project-view/29271/12996?selectedIssue=368811

Note: This issue was created automatically. Priority was set based on classification
of the file affected and the impact field in coverity. Assignees were set using the MAINTAINERS file.

Metadata

Metadata

Labels

CoverityA Coverity detected issue or its fixarea: SensorsSensorsbugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions