summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-06 13:59:14 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-06 13:59:14 -0700
commitb1538c809d0ce5abe489822f9d2b21287a0a38d5 (patch)
tree303fbcb44fbd14d0039293cdc7e9a34e8b2424ba
parente76675d4df466448a33532895dd371aa498a0e49 (diff)
downloadsubsurface-b1538c809d0ce5abe489822f9d2b21287a0a38d5.tar.gz
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>
-rw-r--r--datatrak.c8
-rw-r--r--datatrak.h4
-rw-r--r--liquivision.c8
-rw-r--r--planner.c5
-rw-r--r--qt-ui/preferences.cpp2
-rw-r--r--qtserialbluetooth.cpp6
6 files changed, 18 insertions, 15 deletions
diff --git a/datatrak.c b/datatrak.c
index 414195c2b..c2764b4ef 100644
--- a/datatrak.c
+++ b/datatrak.c
@@ -62,7 +62,7 @@ static unsigned char to_8859(unsigned char char_cp850)
static char *to_utf8(unsigned char *in_string)
{
int outlen, inlen, i = 0, j = 0;
- inlen = strlen(in_string);
+ inlen = strlen((char *)in_string);
outlen = inlen * 2 + 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;
unsigned char *tmp_string1 = NULL,
*locality = NULL,
- *dive_point = NULL,
- buffer[1024];
+ *dive_point = NULL;
+ char buffer[1024];
struct divecomputer *dc = &dt_dive->dc;
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);
if (tmp_1byte != 0) {
read_string(tmp_string1);
- dt_dive->buddy = strdup(tmp_string1);
+ dt_dive->buddy = strdup((char *)tmp_string1);
free(tmp_string1);
}
diff --git a/datatrak.h b/datatrak.h
index a86a6af0a..4e3ccd1a4 100644
--- a/datatrak.h
+++ b/datatrak.h
@@ -28,7 +28,7 @@ typedef struct dtrakheader_ {
#define read_string(_property) \
_property = (unsigned char *)calloc(tmp_1byte + 1, 1); \
- fread(_property, 1, tmp_1byte, archivo); \
- _property = strcat(to_utf8(_property), "");
+ fread((char *)_property, 1, tmp_1byte, archivo); \
+ _property = (unsigned char *)strcat(to_utf8(_property), "");
#endif // DATATRAK_HEADER_H
diff --git a/liquivision.c b/liquivision.c
index cabfa0b17..957e7ccf9 100644
--- a/liquivision.c
+++ b/liquivision.c
@@ -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, buf + ptr + len + 4, place_len);
} else if (len) {
- location = strndup(buf + ptr, len);
+ location = strndup((char *)buf + ptr, 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 */
@@ -160,8 +160,8 @@ static void parse_dives (int log_version, const unsigned char *buf, unsigned int
ptr += 4;
// Blank notes are better than the default text
- if (len && strncmp(buf + ptr, "Comment ...", 11)) {
- dive->notes = strndup(buf + ptr, len);
+ if (len && strncmp((char *)buf + ptr, "Comment ...", 11)) {
+ dive->notes = strndup((char *)buf + ptr, len);
}
ptr += len;
diff --git a/planner.c b/planner.c
index b04c835ef..8569fc904 100644
--- a/planner.c
+++ b/planner.c
@@ -624,8 +624,9 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
}
}
} else {
- if (plan_display_transitions || dp->entered || !dp->next || (nextdp && dp->depth != nextdp->depth) ||
- !isascent && gaschange_before && ((nextdp && dp->depth != nextdp->depth) || gaschange_after) ||
+ if (plan_display_transitions || dp->entered || !dp->next ||
+ (nextdp && dp->depth != nextdp->depth) ||
+ (!isascent && gaschange_before && nextdp && dp->depth != nextdp->depth) || gaschange_after ||
(isascent && gaschange_after && nextdp && dp->depth != nextdp->depth )) {
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);
diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp
index c9c44adc7..b30e76e03 100644
--- a/qt-ui/preferences.cpp
+++ b/qt-ui/preferences.cpp
@@ -417,7 +417,7 @@ void PreferencesDialog::syncSettings()
if (!email.isEmpty() && !password.isEmpty()) {
// connect to backend server to check / create credentials
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 '+'.")));
} else {
CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
diff --git a/qtserialbluetooth.cpp b/qtserialbluetooth.cpp
index 1f0ed6b47..dc67cf17f 100644
--- a/qtserialbluetooth.cpp
+++ b/qtserialbluetooth.cpp
@@ -121,7 +121,8 @@ static int qt_serial_read(serial_t *device, void* data, unsigned int size)
if (device == NULL || device->socket == NULL)
return DC_STATUS_INVALIDARGS;
- unsigned int nbytes = 0, rc;
+ unsigned int nbytes = 0;
+ int rc;
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)
return DC_STATUS_INVALIDARGS;
- unsigned int nbytes = 0, rc;
+ unsigned int nbytes = 0;
+ int rc;
while(nbytes < size)
{