From aa50be9cd581f9ba66afebe103c90263b74a6ec0 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 20 Sep 2022 09:33:07 -0700 Subject: [PATCH] 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 0c84f369c35b ("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 --- core/load-git.c | 2 +- core/parse.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/load-git.c b/core/load-git.c index a5dbf9ccc..0b6d877a6 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -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; } diff --git a/core/parse.c b/core/parse.c index e8161b395..fddcdeff4 100644 --- a/core/parse.c +++ b/core/parse.c @@ -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; }