mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Code cleanup
Make precedence of && over || explicit. Explicitly convert between char * and unsigned char *. Don't assign potentially negative return code to an unsigend variable. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
e76675d4df
commit
b1538c809d
6 changed files with 18 additions and 15 deletions
|
@ -62,7 +62,7 @@ static unsigned char to_8859(unsigned char char_cp850)
|
||||||
static char *to_utf8(unsigned char *in_string)
|
static char *to_utf8(unsigned char *in_string)
|
||||||
{
|
{
|
||||||
int outlen, inlen, i = 0, j = 0;
|
int outlen, inlen, i = 0, j = 0;
|
||||||
inlen = strlen(in_string);
|
inlen = strlen((char *)in_string);
|
||||||
outlen = inlen * 2 + 1;
|
outlen = inlen * 2 + 1;
|
||||||
|
|
||||||
char *out_string = calloc(outlen, 1);
|
char *out_string = calloc(outlen, 1);
|
||||||
|
@ -165,8 +165,8 @@ static struct dive dt_dive_parser(FILE *archivo, struct dive *dt_dive)
|
||||||
char *tmp_notes_str = NULL;
|
char *tmp_notes_str = NULL;
|
||||||
unsigned char *tmp_string1 = NULL,
|
unsigned char *tmp_string1 = NULL,
|
||||||
*locality = NULL,
|
*locality = NULL,
|
||||||
*dive_point = NULL,
|
*dive_point = NULL;
|
||||||
buffer[1024];
|
char buffer[1024];
|
||||||
struct divecomputer *dc = &dt_dive->dc;
|
struct divecomputer *dc = &dt_dive->dc;
|
||||||
|
|
||||||
is_nitrox = is_O2 = is_SCR = 0;
|
is_nitrox = is_O2 = is_SCR = 0;
|
||||||
|
@ -475,7 +475,7 @@ static struct dive dt_dive_parser(FILE *archivo, struct dive *dt_dive)
|
||||||
read_bytes(1);
|
read_bytes(1);
|
||||||
if (tmp_1byte != 0) {
|
if (tmp_1byte != 0) {
|
||||||
read_string(tmp_string1);
|
read_string(tmp_string1);
|
||||||
dt_dive->buddy = strdup(tmp_string1);
|
dt_dive->buddy = strdup((char *)tmp_string1);
|
||||||
free(tmp_string1);
|
free(tmp_string1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ typedef struct dtrakheader_ {
|
||||||
|
|
||||||
#define read_string(_property) \
|
#define read_string(_property) \
|
||||||
_property = (unsigned char *)calloc(tmp_1byte + 1, 1); \
|
_property = (unsigned char *)calloc(tmp_1byte + 1, 1); \
|
||||||
fread(_property, 1, tmp_1byte, archivo); \
|
fread((char *)_property, 1, tmp_1byte, archivo); \
|
||||||
_property = strcat(to_utf8(_property), "");
|
_property = (unsigned char *)strcat(to_utf8(_property), "");
|
||||||
|
|
||||||
#endif // DATATRAK_HEADER_H
|
#endif // DATATRAK_HEADER_H
|
||||||
|
|
|
@ -142,9 +142,9 @@ static void parse_dives (int log_version, const unsigned char *buf, unsigned int
|
||||||
memcpy(location + len, ", ", 2);
|
memcpy(location + len, ", ", 2);
|
||||||
memcpy(location + len + 2, buf + ptr + len + 4, place_len);
|
memcpy(location + len + 2, buf + ptr + len + 4, place_len);
|
||||||
} else if (len) {
|
} else if (len) {
|
||||||
location = strndup(buf + ptr, len);
|
location = strndup((char *)buf + ptr, len);
|
||||||
} else if (place_len) {
|
} else if (place_len) {
|
||||||
location = strndup(buf + ptr + len + 4, place_len);
|
location = strndup((char *)buf + ptr + len + 4, place_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Store the location only if we have one */
|
/* Store the location only if we have one */
|
||||||
|
@ -160,8 +160,8 @@ static void parse_dives (int log_version, const unsigned char *buf, unsigned int
|
||||||
ptr += 4;
|
ptr += 4;
|
||||||
|
|
||||||
// Blank notes are better than the default text
|
// Blank notes are better than the default text
|
||||||
if (len && strncmp(buf + ptr, "Comment ...", 11)) {
|
if (len && strncmp((char *)buf + ptr, "Comment ...", 11)) {
|
||||||
dive->notes = strndup(buf + ptr, len);
|
dive->notes = strndup((char *)buf + ptr, len);
|
||||||
}
|
}
|
||||||
ptr += len;
|
ptr += len;
|
||||||
|
|
||||||
|
|
|
@ -624,8 +624,9 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (plan_display_transitions || dp->entered || !dp->next || (nextdp && dp->depth != nextdp->depth) ||
|
if (plan_display_transitions || dp->entered || !dp->next ||
|
||||||
!isascent && gaschange_before && ((nextdp && dp->depth != nextdp->depth) || gaschange_after) ||
|
(nextdp && dp->depth != nextdp->depth) ||
|
||||||
|
(!isascent && gaschange_before && nextdp && dp->depth != nextdp->depth) || gaschange_after ||
|
||||||
(isascent && gaschange_after && nextdp && dp->depth != nextdp->depth )) {
|
(isascent && gaschange_after && nextdp && dp->depth != nextdp->depth )) {
|
||||||
snprintf(temp, sizeof(temp), translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit);
|
snprintf(temp, sizeof(temp), translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit);
|
||||||
len += snprintf(buffer + len, sizeof(buffer) - len, "<tr><td style='padding-left: 10px; float: right;'>%s</td>", temp);
|
len += snprintf(buffer + len, sizeof(buffer) - len, "<tr><td style='padding-left: 10px; float: right;'>%s</td>", temp);
|
||||||
|
|
|
@ -417,7 +417,7 @@ void PreferencesDialog::syncSettings()
|
||||||
if (!email.isEmpty() && !password.isEmpty()) {
|
if (!email.isEmpty() && !password.isEmpty()) {
|
||||||
// connect to backend server to check / create credentials
|
// connect to backend server to check / create credentials
|
||||||
QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$");
|
QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$");
|
||||||
if (!reg.match(email).hasMatch() || !password.isEmpty() && !reg.match(password).hasMatch()) {
|
if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) {
|
||||||
report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
|
report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
|
||||||
} else {
|
} else {
|
||||||
CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
|
CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
|
||||||
|
|
|
@ -121,7 +121,8 @@ static int qt_serial_read(serial_t *device, void* data, unsigned int size)
|
||||||
if (device == NULL || device->socket == NULL)
|
if (device == NULL || device->socket == NULL)
|
||||||
return DC_STATUS_INVALIDARGS;
|
return DC_STATUS_INVALIDARGS;
|
||||||
|
|
||||||
unsigned int nbytes = 0, rc;
|
unsigned int nbytes = 0;
|
||||||
|
int rc;
|
||||||
|
|
||||||
while(nbytes < size)
|
while(nbytes < size)
|
||||||
{
|
{
|
||||||
|
@ -152,7 +153,8 @@ static int qt_serial_write(serial_t *device, const void* data, unsigned int size
|
||||||
if (device == NULL || device->socket == NULL)
|
if (device == NULL || device->socket == NULL)
|
||||||
return DC_STATUS_INVALIDARGS;
|
return DC_STATUS_INVALIDARGS;
|
||||||
|
|
||||||
unsigned int nbytes = 0, rc;
|
unsigned int nbytes = 0;
|
||||||
|
int rc;
|
||||||
|
|
||||||
while(nbytes < size)
|
while(nbytes < size)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue