Merge branch 'warnings'

This commit is contained in:
Jef Driesen 2021-01-05 13:01:48 +01:00
commit 4ffd45c126
19 changed files with 52 additions and 56 deletions

View File

@ -240,7 +240,8 @@ main (int argc, char *argv[])
}
// Translate the help option into a command.
char *argv_help[] = {(char *) "help", NULL, NULL};
char helpcmd[] = "help";
char *argv_help[] = {helpcmd, NULL, NULL};
if (help || argv[0] == NULL) {
if (argv[0]) {
argv_help[1] = argv[0];

View File

@ -152,7 +152,7 @@ dctool_parse_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
goto cleanup;
}
for (unsigned int i = 0; i < argc; ++i) {
for (int i = 0; i < argc; ++i) {
// Read the input file.
buffer = dctool_file_read (argv[i]);
if (buffer == NULL) {

View File

@ -80,7 +80,7 @@ mktemplate_datetime (char *buffer, size_t size, dc_parser_t *parser)
n = snprintf (buffer, size, "%04i%02i%02iT%02i%02i%02i",
datetime.year, datetime.month, datetime.day,
datetime.hour, datetime.minute, datetime.second);
if (n < 0 || n >= size)
if (n < 0 || (size_t) n >= size)
return -1;
return n;
@ -92,7 +92,7 @@ mktemplate_number (char *buffer, size_t size, unsigned int number)
int n = 0;
n = snprintf (buffer, size, "%04u", number);
if (n < 0 || n >= size)
if (n < 0 || (size_t) n >= size)
return -1;
return n;

View File

@ -22,11 +22,13 @@
#ifndef DC_DATETIME_H
#define DC_DATETIME_H
#include <limits.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define DC_TIMEZONE_NONE 0x80000000
#define DC_TIMEZONE_NONE INT_MIN
#if defined (_WIN32) && !defined (__GNUC__)
typedef __int64 dc_ticks_t;

View File

@ -41,6 +41,8 @@
#define COCHRAN_MODEL_EMC_16 4
#define COCHRAN_MODEL_EMC_20 5
#define UNDEFINED 0xFFFFFFFF
typedef enum cochran_endian_t {
ENDIAN_LE,
ENDIAN_BE,
@ -57,8 +59,8 @@ typedef struct cochran_data_t {
unsigned char *logbook;
unsigned short int dive_count;
int fp_dive_num;
int invalid_profile_dive_num;
unsigned int fp_dive_num;
unsigned int invalid_profile_dive_num;
unsigned int logbook_size;
} cochran_data_t;
@ -621,18 +623,17 @@ cochran_commander_find_fingerprint(cochran_commander_device_t *device, cochran_d
// We track profile ringbuffer usage to determine which dives have profile data
int profile_capacity_remaining = device->layout->rb_profile_end - device->layout->rb_profile_begin;
int dive_count = -1;
data->fp_dive_num = -1;
unsigned int dive_count = 0;
data->fp_dive_num = UNDEFINED;
// Start at end of log
if (data->dive_count < device->layout->rb_logbook_entry_count)
dive_count = data->dive_count;
else
dive_count = device->layout->rb_logbook_entry_count;
dive_count--;
unsigned int sample_read_size = 0;
data->invalid_profile_dive_num = -1;
data->invalid_profile_dive_num = UNDEFINED;
// Remove the pre-dive events that occur after the last dive
unsigned int rb_head_ptr = 0;
@ -676,7 +677,7 @@ cochran_commander_find_fingerprint(cochran_commander_device_t *device, cochran_d
// Loop through dives to find FP, Accumulate profile data size,
// and find the last dive with invalid profile
for (unsigned int i = 0; i <= dive_count; ++i) {
for (unsigned int i = 0; i < dive_count; ++i) {
unsigned int idx = (device->layout->rb_logbook_entry_count + head_dive - (i + 1)) % device->layout->rb_logbook_entry_count;
unsigned char *log_entry = data->logbook + idx * device->layout->rb_logbook_entry_size;
@ -953,7 +954,7 @@ cochran_commander_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
}
// Change tail to dive following the fingerprint dive.
if (data.fp_dive_num > -1)
if (data.fp_dive_num != UNDEFINED)
tail_dive = (data.fp_dive_num + 1) % layout->rb_logbook_entry_count;
// Number of dives to read

View File

@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <limits.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
@ -77,7 +78,7 @@ l_vsnprintf (char *str, size_t size, const char *format, va_list ap)
* enough.
*/
n = vsnprintf (str, size, format, ap);
if (n >= size)
if (n >= 0 && (size_t) n >= size)
n = -1;
#endif
@ -104,7 +105,7 @@ l_hexdump (char *str, size_t size, const unsigned char data[], size_t n)
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
if (size == 0)
if (size == 0 || size > INT_MAX)
return -1;
/* The maximum number of bytes. */
@ -126,11 +127,11 @@ l_hexdump (char *str, size_t size, const unsigned char data[], size_t n)
/* Null terminate the hex string. */
str[length * 2] = 0;
return (n > maxlength ? -1 : length * 2);
return (n > maxlength ? -1 : (int) (length * 2));
}
static void
logfunc (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *msg, void *userdata)
loghandler (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *msg, void *userdata)
{
const char *loglevels[] = {"NONE", "ERROR", "WARNING", "INFO", "DEBUG", "ALL"};
@ -166,7 +167,7 @@ dc_context_new (dc_context_t **out)
#ifdef ENABLE_LOGGING
context->loglevel = DC_LOGLEVEL_WARNING;
context->logfunc = logfunc;
context->logfunc = loghandler;
#else
context->loglevel = DC_LOGLEVEL_NONE;
context->logfunc = NULL;

View File

@ -1024,7 +1024,7 @@ hw_ostc3_firmware_readline (FILE *fp, dc_context_t *context, unsigned int addr,
unsigned char ascii[39];
unsigned char faddr_byte[3];
unsigned int faddr = 0;
int n = 0;
size_t n = 0;
if (size > 16) {
ERROR (context, "Invalid arguments.");

View File

@ -390,7 +390,6 @@ hw_ostc_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime)
{
hw_ostc_parser_t *parser = (hw_ostc_parser_t *) abstract;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;
// Cache the header data.
dc_status_t rc = hw_ostc_parser_cache (parser);
@ -451,7 +450,6 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned
{
hw_ostc_parser_t *parser = (hw_ostc_parser_t *) abstract;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;
// Cache the header data.
dc_status_t rc = hw_ostc_parser_cache (parser);

View File

@ -155,7 +155,7 @@ dc_irda_iterator_new (dc_iterator_t **out, dc_context_t *context, dc_descriptor_
}
// Open the socket.
int fd = socket (AF_IRDA, SOCK_STREAM, 0);
s_socket_t fd = socket (AF_IRDA, SOCK_STREAM, 0);
if (fd == S_INVALID) {
s_errcode_t errcode = S_ERRNO;
SYSERROR (context, errcode);

View File

@ -527,9 +527,7 @@ oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns
{
dc_status_t status = DC_STATUS_SUCCESS;
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) abstract;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;
// Cache the header data.
status = oceanic_atom2_parser_cache (parser);

View File

@ -592,8 +592,8 @@ oceanic_vtpro_device_version (dc_device_t *abstract, unsigned char data[], unsig
return rc;
// Verify the checksum of the answer.
unsigned char crc = answer[PAGESIZE / 2];
unsigned char ccrc = checksum_add_uint4 (answer, PAGESIZE / 2, 0x00);
crc = answer[PAGESIZE / 2];
ccrc = checksum_add_uint4 (answer, PAGESIZE / 2, 0x00);
if (crc != ccrc) {
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;

View File

@ -163,8 +163,8 @@ reefnet_sensuspro_parser_get_field (dc_parser_t *abstract, dc_field_type_t type,
while (offset + sizeof (footer) <= size &&
memcmp (data + offset, footer, sizeof (footer)) != 0)
{
unsigned int value = array_uint16_le (data + offset);
unsigned int depth = (value & 0x01FF);
unsigned int raw = array_uint16_le (data + offset);
unsigned int depth = (raw & 0x01FF);
if (depth > maxdepth)
maxdepth = depth;

View File

@ -261,7 +261,8 @@ suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], u
}
// Verify the size of the package.
if (array_uint16_be (answer + 1) + 4 != asize) {
unsigned int len = array_uint16_be (answer + 1);
if (len + 4 != asize) {
ERROR (abstract->context, "Unexpected answer size.");
return DC_STATUS_PROTOCOL;
}

View File

@ -348,9 +348,7 @@ static dc_status_t
suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value)
{
suunto_d9_parser_t *parser = (suunto_d9_parser_t*) abstract;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;
// Cache the gas mix data.
dc_status_t rc = suunto_d9_parser_cache (parser);

View File

@ -95,7 +95,7 @@ typedef struct suunto_eonsteel_parser_t {
} cache;
} suunto_eonsteel_parser_t;
typedef int (*eon_data_cb_t)(unsigned short type, const struct type_desc *desc, const unsigned char *data, int len, void *user);
typedef int (*eon_data_cb_t)(unsigned short type, const struct type_desc *desc, const unsigned char *data, unsigned int len, void *user);
typedef struct eon_event_t {
const char *name;
@ -137,7 +137,6 @@ static const struct {
static enum eon_sample lookup_descriptor_type(suunto_eonsteel_parser_t *eon, struct type_desc *desc)
{
int i;
const char *name = desc->desc;
// Not a sample type? Skip it
@ -160,7 +159,7 @@ static enum eon_sample lookup_descriptor_type(suunto_eonsteel_parser_t *eon, str
name += 8;
// .. and look it up in the table of sample type strings
for (i = 0; i < C_ARRAY_SIZE(type_translation); i++) {
for (size_t i = 0; i < C_ARRAY_SIZE(type_translation); i++) {
if (!strcmp(name, type_translation[i].name))
return type_translation[i].type;
}
@ -179,8 +178,7 @@ static parser_sample_event_t lookup_event(const char *name, const eon_event_t ev
static const char *desc_type_name(enum eon_sample type)
{
int i;
for (i = 0; i < C_ARRAY_SIZE(type_translation); i++) {
for (size_t i = 0; i < C_ARRAY_SIZE(type_translation); i++) {
if (type == type_translation[i].type)
return type_translation[i].name;
}
@ -366,10 +364,10 @@ static int record_type(suunto_eonsteel_parser_t *eon, unsigned short type, const
return 0;
}
static int traverse_entry(suunto_eonsteel_parser_t *eon, const unsigned char *p, int len, eon_data_cb_t callback, void *user)
static int traverse_entry(suunto_eonsteel_parser_t *eon, const unsigned char *p, int size, eon_data_cb_t callback, void *user)
{
const unsigned char *name, *data, *end, *last, *one_past_end = p + len;
int textlen, type;
const unsigned char *name, *data, *end, *last, *one_past_end = p + size;
int textlen, id;
int rc;
// First two bytes: zero and text length
@ -388,7 +386,7 @@ static int traverse_entry(suunto_eonsteel_parser_t *eon, const unsigned char *p,
// Two bytes of 'type' followed by the name/descriptor, followed by the data
data = name + textlen;
type = array_uint16_le(name);
id = array_uint16_le(name);
name += 2;
if (*name != '<') {
@ -396,7 +394,7 @@ static int traverse_entry(suunto_eonsteel_parser_t *eon, const unsigned char *p,
return -1;
}
record_type(eon, type, (const char *) name, textlen-3);
record_type(eon, id, (const char *) name, textlen-3);
end = data;
last = data;
@ -860,7 +858,7 @@ static void sample_setpoint_automatic(struct sample_data *info, unsigned char va
DEBUG(info->eon->base.context, "sample_setpoint_automatic(%u)", value);
}
static int handle_sample_type(const struct type_desc *desc, struct sample_data *info, enum eon_sample type, const unsigned char *data)
static unsigned int handle_sample_type(const struct type_desc *desc, struct sample_data *info, enum eon_sample type, const unsigned char *data)
{
switch (type) {
case ES_dtime:
@ -968,7 +966,7 @@ static int handle_sample_type(const struct type_desc *desc, struct sample_data *
}
}
static int traverse_samples(unsigned short type, const struct type_desc *desc, const unsigned char *data, int len, void *user)
static int traverse_samples(unsigned short type, const struct type_desc *desc, const unsigned char *data, unsigned int len, void *user)
{
struct sample_data *info = (struct sample_data *) user;
suunto_eonsteel_parser_t *eon = info->eon;
@ -982,8 +980,7 @@ static int traverse_samples(unsigned short type, const struct type_desc *desc, c
info->ceiling = 0.0;
for (i = 0; i < EON_MAX_GROUP; i++) {
enum eon_sample type = desc->type[i];
int bytes = handle_sample_type(desc, info, type, data);
unsigned int bytes = handle_sample_type(desc, info, desc->type[i], data);
if (!bytes)
break;
@ -1246,8 +1243,6 @@ static float get_le32_float(const unsigned char *src)
static int traverse_device_fields(suunto_eonsteel_parser_t *eon, const struct type_desc *desc,
const unsigned char *data, int len)
{
const char *name = desc->desc + strlen("sml.DeviceLog.Device.");
return 0;
}
@ -1429,13 +1424,15 @@ static int traverse_sample_fields(suunto_eonsteel_parser_t *eon, const struct ty
set_depth_field(eon, array_uint16_le(data));
data += 2;
continue;
default:
break;
}
break;
}
return 0;
}
static int traverse_fields(unsigned short type, const struct type_desc *desc, const unsigned char *data, int len, void *user)
static int traverse_fields(unsigned short type, const struct type_desc *desc, const unsigned char *data, unsigned int len, void *user)
{
suunto_eonsteel_parser_t *eon = (suunto_eonsteel_parser_t *) user;

View File

@ -110,10 +110,10 @@ suunto_solution_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, u
unsigned int depth = 0, maxdepth = 0;
unsigned int offset = 3;
while (offset < size && data[offset] != 0x80) {
unsigned char value = data[offset++];
if (value < 0x7e || value > 0x82) {
depth += (signed char) value;
if (value == 0x7D || value == 0x83) {
unsigned char raw = data[offset++];
if (raw < 0x7e || raw > 0x82) {
depth += (signed char) raw;
if (raw == 0x7D || raw == 0x83) {
if (offset + 1 > size)
return DC_STATUS_DATAFORMAT;
depth += (signed char) data[offset++];

View File

@ -252,7 +252,8 @@ suunto_vyper2_device_packet (dc_device_t *abstract, const unsigned char command[
}
// Verify the size of the package.
if (array_uint16_be (answer + 1) + 4 != asize) {
unsigned int len = array_uint16_be (answer + 1);
if (len + 4 != asize) {
ERROR (abstract->context, "Unexpected answer size.");
return DC_STATUS_PROTOCOL;
}

View File

@ -234,9 +234,7 @@ static dc_status_t
suunto_vyper_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value)
{
suunto_vyper_parser_t *parser = (suunto_vyper_parser_t *) abstract;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;
dc_gasmix_t *gas = (dc_gasmix_t *) value;
dc_tank_t *tank = (dc_tank_t *) value;

View File

@ -777,7 +777,7 @@ dc_usbhid_write (dc_iostream_t *abstract, const void *data, size_t size, size_t
out:
#ifdef _WIN32
if (nbytes > size) {
if ((size_t) nbytes > size) {
WARNING (abstract->context, "Number of bytes exceeds the buffer size (" DC_PRINTF_SIZE " > " DC_PRINTF_SIZE ")!", nbytes, size);
nbytes = size;
}