mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Warnings: silence new gcc warnings in uemis-downloader.c
Since upgrading to gcc 8.2 it produces noisy warnings about potentially truncated strings. It doesn't recognize that filenr can never become >4000. So clamp it down explicitly. Do this by adding a function that does the assembly of the filename path. Adding unnecessary code to silence compiler warnings is dubious, but in this case it might be reasonable. Fix a second instance by increasing the stack-allocated buffer to 32 bytes. Hopefully nobody has more divespots than would fit in a 9-decimal digit number! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
0fc58f4534
commit
26a4fb5632
1 changed files with 22 additions and 13 deletions
|
@ -516,6 +516,22 @@ static void uemis_increased_timeout(int *timeout)
|
||||||
usleep(*timeout);
|
usleep(*timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *build_ans_path(const char *path, int filenr)
|
||||||
|
{
|
||||||
|
char *intermediate, *ans_path, fl[13];
|
||||||
|
|
||||||
|
/* Clamp filenr into the 0..9999 range. This is never necessary,
|
||||||
|
* as filenr can never go above UEMIS_MAX_FILES, but gcc doesn't
|
||||||
|
* recognize that and produces very noisy warnings. */
|
||||||
|
filenr = filenr < 0 ? 0 : filenr % 10000;
|
||||||
|
|
||||||
|
snprintf(fl, 13, "ANS%d.TXT", filenr);
|
||||||
|
intermediate = build_filename(path, "ANS");
|
||||||
|
ans_path = build_filename(intermediate, fl);
|
||||||
|
free(intermediate);
|
||||||
|
return ans_path;
|
||||||
|
}
|
||||||
|
|
||||||
/* send a request to the dive computer and collect the answer */
|
/* send a request to the dive computer and collect the answer */
|
||||||
static bool uemis_get_answer(const char *path, char *request, int n_param_in,
|
static bool uemis_get_answer(const char *path, char *request, int n_param_in,
|
||||||
int n_param_out, const char **error_text)
|
int n_param_out, const char **error_text)
|
||||||
|
@ -583,8 +599,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
|
||||||
if (import_thread_cancelled)
|
if (import_thread_cancelled)
|
||||||
return false;
|
return false;
|
||||||
progress_bar_fraction = filenr / (double)UEMIS_MAX_FILES;
|
progress_bar_fraction = filenr / (double)UEMIS_MAX_FILES;
|
||||||
snprintf(fl, 13, "ANS%d.TXT", filenr - 1);
|
ans_path = build_ans_path(path, filenr - 1);
|
||||||
ans_path = build_filename(build_filename(path, "ANS"), fl);
|
|
||||||
ans_file = subsurface_open(ans_path, O_RDONLY, 0666);
|
ans_file = subsurface_open(ans_path, O_RDONLY, 0666);
|
||||||
if (ans_file < 0) {
|
if (ans_file < 0) {
|
||||||
*error_text = "can't open Uemis response file";
|
*error_text = "can't open Uemis response file";
|
||||||
|
@ -648,10 +663,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
|
||||||
}
|
}
|
||||||
if (ismulti && more_files && tmp[0] == '1') {
|
if (ismulti && more_files && tmp[0] == '1') {
|
||||||
int size;
|
int size;
|
||||||
snprintf(fl, 13, "ANS%d.TXT", assembling_mbuf ? filenr - 2 : filenr - 1);
|
ans_path = build_ans_path(path, assembling_mbuf ? filenr - 2 : filenr - 1);
|
||||||
char *intermediate = build_filename(path, "ANS");
|
|
||||||
ans_path = build_filename(intermediate, fl);
|
|
||||||
free(intermediate);
|
|
||||||
ans_file = subsurface_open(ans_path, O_RDONLY, 0666);
|
ans_file = subsurface_open(ans_path, O_RDONLY, 0666);
|
||||||
if (ans_file < 0) {
|
if (ans_file < 0) {
|
||||||
*error_text = "can't open Uemis response file";
|
*error_text = "can't open Uemis response file";
|
||||||
|
@ -688,10 +700,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
|
||||||
if (!ismulti) {
|
if (!ismulti) {
|
||||||
snprintf(fl, 13, "ANS%d.TXT", filenr - 1);
|
ans_path = build_ans_path(path, filenr - 1);
|
||||||
char *intermediate = build_filename(path, "ANS");
|
|
||||||
ans_path = build_filename(intermediate, fl);
|
|
||||||
free(intermediate);
|
|
||||||
ans_file = subsurface_open(ans_path, O_RDONLY, 0666);
|
ans_file = subsurface_open(ans_path, O_RDONLY, 0666);
|
||||||
if (ans_file < 0) {
|
if (ans_file < 0) {
|
||||||
*error_text = "can't open Uemis response file";
|
*error_text = "can't open Uemis response file";
|
||||||
|
@ -701,7 +710,6 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(ans_path);
|
|
||||||
size = bytes_available(ans_file);
|
size = bytes_available(ans_file);
|
||||||
if (size > 3) {
|
if (size > 3) {
|
||||||
int r;
|
int r;
|
||||||
|
@ -716,10 +724,11 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
|
||||||
buffer_add(&mbuf, &mbuf_size, buf);
|
buffer_add(&mbuf, &mbuf_size, buf);
|
||||||
show_progress(buf, what);
|
show_progress(buf, what);
|
||||||
#if UEMIS_DEBUG & 8
|
#if UEMIS_DEBUG & 8
|
||||||
fprintf(debugfile, "::r %s \"%s\"\n", fl, buf);
|
fprintf(debugfile, "::r %s \"%s\"\n", ans_path, buf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
size -= 3;
|
size -= 3;
|
||||||
|
free(ans_path);
|
||||||
close(ans_file);
|
close(ans_file);
|
||||||
} else {
|
} else {
|
||||||
ismulti = false;
|
ismulti = false;
|
||||||
|
@ -1157,7 +1166,7 @@ static void do_delete_dives(struct dive_table *td, int idx)
|
||||||
|
|
||||||
static bool load_uemis_divespot(const char *mountpath, int divespot_id)
|
static bool load_uemis_divespot(const char *mountpath, int divespot_id)
|
||||||
{
|
{
|
||||||
char divespotnr[10];
|
char divespotnr[32];
|
||||||
snprintf(divespotnr, sizeof(divespotnr), "%d", divespot_id);
|
snprintf(divespotnr, sizeof(divespotnr), "%d", divespot_id);
|
||||||
param_buff[2] = divespotnr;
|
param_buff[2] = divespotnr;
|
||||||
#if UEMIS_DEBUG & 2
|
#if UEMIS_DEBUG & 2
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue