Use the right type for sanitize_sensor_id()

It returned a 'uint8_t', which clashes pretty badly with NO_SENSOR being
-1, and turned it into 255.  That then ended up historically working,
because before commit 0c84f369c3 ("core: use int16_t for sensor-id")
we actually did that everywhere:

 #define NO_SENSOR ((uint8_t)-1)
 ...
    uint8_t sensor[MAX_SENSORS];

but that was changed to

 #define NO_SENSOR -1
 ...
    int16_t sensor[MAX_SENSORS];

and this helper type became wrong.

Just make it return 'int', avoiding any type narrowing issues.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2022-09-20 09:33:07 -07:00
parent 3446dd5125
commit aa50be9cd5
2 changed files with 2 additions and 2 deletions

View file

@ -644,7 +644,7 @@ static char *parse_sample_unit(struct sample *sample, double val, char *unit)
/*
* If the given cylinder doesn't exist, return NO_SENSOR.
*/
static uint8_t sanitize_sensor_id(const struct dive *d, int nr)
static int sanitize_sensor_id(const struct dive *d, int nr)
{
return d && nr >= 0 && nr < d->cylinders.nr ? nr : NO_SENSOR;
}

View file

@ -393,7 +393,7 @@ void ws_end(struct parser_state *state)
/*
* If the given cylinder doesn't exist, return NO_SENSOR.
*/
static uint8_t sanitize_sensor_id(const struct dive *d, int nr)
static int sanitize_sensor_id(const struct dive *d, int nr)
{
return d && nr >= 0 && nr < d->cylinders.nr ? nr : NO_SENSOR;
}