Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some Codacy warnings #6576

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2482,9 +2482,9 @@ static CURLcode ftp_state_get_resp(struct Curl_easy *data,
bytes--;
}
/* if we have nothing but digits: */
if(bytes++) {
if(bytes) {
/* get the number! */
(void)curlx_strtoofft(bytes, NULL, 0, &size);
(void)curlx_strtoofft(++bytes, NULL, 0, &size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick: wouldn't it be more readable to just do bytes++; on its own line before the curlx_strtoofft call?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for me too. Personally, I find both equally readable. What do others think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As much as I like terse code, ++bytes; on a separate line makes it easier not to miss. It's not a strong opinion, however.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm equally fine with either.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it on a separate line in the final commit that landed on master.

}
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/ftplistparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,6 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
else if(c == '\n') {
parser->offsets.filename = parser->item_offset;
finfo->b_data[finfo->b_used - 1] = 0;
parser->offsets.filename = parser->item_offset;
result = ftp_pl_insert_finfo(data, infop);
if(result) {
parser->error = result;
Expand Down
16 changes: 7 additions & 9 deletions lib/memdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,13 @@ static bool countcheck(const char *func, int line, const char *source)
should not be made */
if(memlimit && source) {
if(!memsize) {
if(source) {
/* log to file */
curl_dbg_log("LIMIT %s:%d %s reached memlimit\n",
source, line, func);
/* log to stderr also */
fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
source, line, func);
fflush(curl_dbg_logfile); /* because it might crash now */
}
/* log to file */
curl_dbg_log("LIMIT %s:%d %s reached memlimit\n",
source, line, func);
/* log to stderr also */
fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
source, line, func);
fflush(curl_dbg_logfile); /* because it might crash now */
errno = ENOMEM;
return TRUE; /* RETURN ERROR! */
}
Expand Down
4 changes: 1 addition & 3 deletions lib/sendf.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,7 @@ static CURLcode pausewrite(struct Curl_easy *data,
/* store this information in the state struct for later use */
Curl_dyn_init(&s->tempwrite[i].b, DYN_PAUSE_BUFFER);
s->tempwrite[i].type = type;

if(newtype)
s->tempcount++;
s->tempcount++;
}

if(Curl_dyn_addn(&s->tempwrite[i].b, (unsigned char *)ptr, len))
Expand Down
6 changes: 0 additions & 6 deletions lib/tftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,6 @@ static CURLcode tftp_set_timeouts(struct tftp_state_data *state)
if(state->retry_max < 1)
/* avoid division by zero below */
state->retry_max = 1;

/* Compute the re-start interval to suit the timeout */
state->retry_time = (int)timeout/state->retry_max;
if(state->retry_time<1)
state->retry_time = 1;

}
else {
if(timeout_ms > 0)
Expand Down
6 changes: 2 additions & 4 deletions lib/vquic/ngtcp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ static int cb_recv_stream_data(ngtcp2_conn *tconn, uint32_t flags,
{
struct quicsocket *qs = (struct quicsocket *)user_data;
ssize_t nconsumed;
int fin = flags & NGTCP2_STREAM_DATA_FLAG_FIN ? 1 : 0;
int fin = (flags & NGTCP2_STREAM_DATA_FLAG_FIN) ? 1 : 0;
(void)offset;
(void)stream_user_data;

Expand Down Expand Up @@ -1291,7 +1291,6 @@ static int cb_h3_acked_stream_data(nghttp3_conn *conn, int64_t stream_id,
{
struct Curl_easy *data = stream_user_data;
struct HTTP *stream = data->req.p.http;
int rv;
(void)user_data;

if(!data->set.postfields) {
Expand All @@ -1302,7 +1301,7 @@ static int cb_h3_acked_stream_data(nghttp3_conn *conn, int64_t stream_id,
DEBUGASSERT(stream->h3out->used < H3_SEND_SIZE);

if(stream->h3out->used == 0) {
rv = nghttp3_conn_resume_stream(conn, stream_id);
int rv = nghttp3_conn_resume_stream(conn, stream_id);
if(rv != 0) {
return NGTCP2_ERR_CALLBACK_FAILURE;
}
Expand Down Expand Up @@ -1788,7 +1787,6 @@ static CURLcode ng_flush_egress(struct Curl_easy *data,
ngtcp2_path_storage_zero(&ps);

for(;;) {
outlen = -1;
veccnt = 0;
stream_id = -1;
fin = 0;
Expand Down
1 change: 0 additions & 1 deletion lib/vtls/gskit.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,6 @@ static CURLcode gskit_connect_step1(struct Curl_easy *data,
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
gsk_handle envir;
CURLcode result;
int rc;
const char * const keyringfile = SSL_CONN_CONFIG(CAfile);
const char * const keyringpwd = SSL_SET_OPTION(key_passwd);
const char * const keyringlabel = SSL_SET_OPTION(primary.clientcert);
Expand Down
9 changes: 3 additions & 6 deletions lib/vtls/nss.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ static CURLcode nss_load_cert(struct ssl_connect_data *ssl,

if(!result && !cacert) {
/* we have successfully loaded a client certificate */
CERTCertificate *cert;
char *nickname = NULL;
char *n = strrchr(filename, '/');
if(n)
Expand All @@ -554,7 +553,7 @@ static CURLcode nss_load_cert(struct ssl_connect_data *ssl,
* <https://bugzilla.redhat.com/733685>. */
nickname = aprintf("PEM Token #1:%s", n);
if(nickname) {
cert = PK11_FindCertFromNickname(nickname, NULL);
CERTCertificate *cert = PK11_FindCertFromNickname(nickname, NULL);
if(cert)
CERT_DestroyCertificate(cert);

Expand Down Expand Up @@ -957,7 +956,6 @@ static CURLcode display_conn_info(struct Curl_easy *data, PRFileDesc *sock)
CERTCertificate *cert2;
CERTCertificate *cert3;
PRTime now;
int i;

if(SSL_GetChannelInfo(sock, &channel, sizeof(channel)) ==
SECSuccess && channel.length == sizeof(channel) &&
Expand All @@ -978,8 +976,8 @@ static CURLcode display_conn_info(struct Curl_easy *data, PRFileDesc *sock)
}
else {
/* Count certificates in chain. */
int i = 1;
now = PR_Now();
i = 1;
if(!cert->isRoot) {
cert2 = CERT_FindCertIssuer(cert, now, certUsageSSLCA);
while(cert2) {
Expand Down Expand Up @@ -1782,12 +1780,11 @@ static CURLcode nss_fail_connect(struct ssl_connect_data *connssl,
struct Curl_easy *data,
CURLcode curlerr)
{
PRErrorCode err = 0;
struct ssl_backend_data *backend = connssl->backend;

if(is_nss_error(curlerr)) {
/* read NSPR error code */
err = PR_GetError();
PRErrorCode err = PR_GetError();
if(is_cc_error(err))
curlerr = CURLE_SSL_CERTPROBLEM;

Expand Down
3 changes: 2 additions & 1 deletion src/tool_paramhlp.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@

struct getout *new_getout(struct OperationConfig *config)
{
static int outnum = 0;
struct getout *node = calloc(1, sizeof(struct getout));
struct getout *last = config->url_last;
if(node) {
static int outnum = 0;

/* append this new node last in the list */
if(last)
last->next = node;
Expand Down
7 changes: 2 additions & 5 deletions tests/libtest/lib543.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ int test(char *URL)
0x1d, 0x57, 0xe1};

CURL *easy;
int asize;
char *s;
CURLcode res = CURLE_OK;
(void)URL;

Expand All @@ -45,9 +43,8 @@ int test(char *URL)
res = TEST_ERR_MAJOR_BAD;
}
else {
asize = (int)sizeof(a);

s = curl_easy_escape(easy, (const char *)a, asize);
int asize = (int)sizeof(a);
char *s = curl_easy_escape(easy, (const char *)a, asize);

if(s) {
printf("%s\n", s);
Expand Down
2 changes: 0 additions & 2 deletions tests/server/mqttd.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,10 @@ static void logprotocol(mqttdir dir,
ssize_t i;
unsigned char *ptr = buffer;
char *optr = data;
ssize_t width = 0;
int left = sizeof(data);

for(i = 0; i<len && (left >= 0); i++) {
msnprintf(optr, left, "%02x", ptr[i]);
width += 2;
optr += 2;
left -= 2;
}
Expand Down
1 change: 0 additions & 1 deletion tests/server/rtspd.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ static int ProcessRequest(struct httprequest *req)
if(!req->pipe &&
req->open &&
req->prot_version >= 11 &&
end &&
req->reqbuf + req->offset > end + strlen(END_OF_HEADERS) &&
(!strncmp(req->reqbuf, "GET", strlen("GET")) ||
!strncmp(req->reqbuf, "HEAD", strlen("HEAD")))) {
Expand Down
5 changes: 2 additions & 3 deletions tests/server/sws.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ static bool socket_domain_is_ip(void)
/* parse the file on disk that might have a test number for us */
static int parse_cmdfile(struct httprequest *req)
{
int testnum = DOCNUMBER_NOTHING;
char buf[256];
FILE *f = fopen(cmdfile, FOPEN_READTEXT);
if(f) {
int testnum = DOCNUMBER_NOTHING;
char buf[256];
while(fgets(buf, sizeof(buf), f)) {
if(1 == sscanf(buf, "Testnum %d", &testnum)) {
logmsg("[%s] cmdfile says testnum %d", cmdfile, testnum);
Expand Down Expand Up @@ -748,7 +748,6 @@ static int ProcessRequest(struct httprequest *req)

if(req->open &&
req->prot_version >= 11 &&
end &&
req->reqbuf + req->offset > end + strlen(end_of_headers) &&
!req->cl &&
(!strncmp(req->reqbuf, "GET", strlen("GET")) ||
Expand Down