1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-24 09:08:49 -05:00

os400.c: fix ASSIGNWITHINCONDITION checksrc warnings

All occurrences of assignment within conditional expression in
os400sys.c rewritten into two steps: first assignment and then the check
on the success of the assignment. Also adjust related incorrect brace
positions to match project indentation style.

This was spurred by seeing "if((inp = input_token))", but while in there
all warnings were fixed.

There should be no functional change from these changes.

Closes #2525
This commit is contained in:
Daniel Gustafsson 2018-04-23 22:29:06 +02:00 committed by Daniel Stenberg
parent 732d093835
commit d25f0a42e8
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -140,7 +140,8 @@ get_buffer(buffer_t * buf, long size)
return buf->buf; return buf->buf;
if(!buf->buf) { if(!buf->buf) {
if((buf->buf = malloc(size))) buf->buf = malloc(size);
if(buf->buf)
buf->size = size; buf->size = size;
return buf->buf; return buf->buf;
@ -156,7 +157,8 @@ get_buffer(buffer_t * buf, long size)
/* Resize the buffer. */ /* Resize the buffer. */
if((cp = realloc(buf->buf, size))) { cp = realloc(buf->buf, size);
if(cp) {
buf->buf = cp; buf->buf = cp;
buf->size = size; buf->size = size;
} }
@ -193,7 +195,8 @@ buffer_threaded(localkey_t key, long size)
/* Allocate buffer descriptors for the current thread. */ /* Allocate buffer descriptors for the current thread. */
if(!(bufs = calloc((size_t) LK_LAST, sizeof *bufs))) bufs = calloc((size_t) LK_LAST, sizeof *bufs);
if(!bufs)
return (char *) NULL; return (char *) NULL;
if(pthread_setspecific(thdkey, (void *) bufs)) { if(pthread_setspecific(thdkey, (void *) bufs)) {
@ -273,15 +276,19 @@ Curl_getnameinfo_a(const struct sockaddr * sa, curl_socklen_t salen,
enodename = (char *) NULL; enodename = (char *) NULL;
eservname = (char *) NULL; eservname = (char *) NULL;
if(nodename && nodenamelen) if(nodename && nodenamelen) {
if(!(enodename = malloc(nodenamelen))) enodename = malloc(nodenamelen);
if(!enodename)
return EAI_MEMORY; return EAI_MEMORY;
}
if(servname && servnamelen) if(servname && servnamelen) {
if(!(eservname = malloc(servnamelen))) { eservname = malloc(servnamelen);
if(!eservname) {
free(enodename); free(enodename);
return EAI_MEMORY; return EAI_MEMORY;
} }
}
status = getnameinfo(sa, salen, enodename, nodenamelen, status = getnameinfo(sa, salen, enodename, nodenamelen,
eservname, servnamelen, flags); eservname, servnamelen, flags);
@ -323,7 +330,8 @@ Curl_getaddrinfo_a(const char * nodename, const char * servname,
if(nodename) { if(nodename) {
i = strlen(nodename); i = strlen(nodename);
if(!(enodename = malloc(i + 1))) enodename = malloc(i + 1);
if(!enodename)
return EAI_MEMORY; return EAI_MEMORY;
i = QadrtConvertA2E(enodename, nodename, i, i); i = QadrtConvertA2E(enodename, nodename, i, i);
@ -333,7 +341,8 @@ Curl_getaddrinfo_a(const char * nodename, const char * servname,
if(servname) { if(servname) {
i = strlen(servname); i = strlen(servname);
if(!(eservname = malloc(i + 1))) { eservname = malloc(i + 1);
if(!eservname) {
free(enodename); free(enodename);
return EAI_MEMORY; return EAI_MEMORY;
} }
@ -385,10 +394,12 @@ Curl_gsk_environment_open(gsk_handle * my_env_handle)
if(!my_env_handle) if(!my_env_handle)
return GSK_OS400_ERROR_INVALID_POINTER; return GSK_OS400_ERROR_INVALID_POINTER;
if(!(p = (struct Curl_gsk_descriptor *) malloc(sizeof *p))) p = (struct Curl_gsk_descriptor *) malloc(sizeof *p);
if(!p)
return GSK_INSUFFICIENT_STORAGE; return GSK_INSUFFICIENT_STORAGE;
p->strlist = (struct gskstrlist *) NULL; p->strlist = (struct gskstrlist *) NULL;
if((rc = gsk_environment_open(&p->h)) != GSK_OK) rc = gsk_environment_open(&p->h);
if(rc != GSK_OK)
free(p); free(p);
else else
*my_env_handle = (gsk_handle) p; *my_env_handle = (gsk_handle) p;
@ -410,10 +421,12 @@ Curl_gsk_secure_soc_open(gsk_handle my_env_handle,
if(!my_session_handle) if(!my_session_handle)
return GSK_OS400_ERROR_INVALID_POINTER; return GSK_OS400_ERROR_INVALID_POINTER;
h = ((struct Curl_gsk_descriptor *) my_env_handle)->h; h = ((struct Curl_gsk_descriptor *) my_env_handle)->h;
if(!(p = (struct Curl_gsk_descriptor *) malloc(sizeof *p))) p = (struct Curl_gsk_descriptor *) malloc(sizeof *p);
if(!p)
return GSK_INSUFFICIENT_STORAGE; return GSK_INSUFFICIENT_STORAGE;
p->strlist = (struct gskstrlist *) NULL; p->strlist = (struct gskstrlist *) NULL;
if((rc = gsk_secure_soc_open(h, &p->h)) != GSK_OK) rc = gsk_secure_soc_open(h, &p->h);
if(rc != GSK_OK)
free(p); free(p);
else else
*my_session_handle = (gsk_handle) p; *my_session_handle = (gsk_handle) p;
@ -448,7 +461,8 @@ Curl_gsk_environment_close(gsk_handle * my_env_handle)
if(!*my_env_handle) if(!*my_env_handle)
return GSK_INVALID_HANDLE; return GSK_INVALID_HANDLE;
p = (struct Curl_gsk_descriptor *) *my_env_handle; p = (struct Curl_gsk_descriptor *) *my_env_handle;
if((rc = gsk_environment_close(&p->h)) == GSK_OK) { rc = gsk_environment_close(&p->h);
if(rc == GSK_OK) {
gsk_free_handle(p); gsk_free_handle(p);
*my_env_handle = (gsk_handle) NULL; *my_env_handle = (gsk_handle) NULL;
} }
@ -468,7 +482,8 @@ Curl_gsk_secure_soc_close(gsk_handle * my_session_handle)
if(!*my_session_handle) if(!*my_session_handle)
return GSK_INVALID_HANDLE; return GSK_INVALID_HANDLE;
p = (struct Curl_gsk_descriptor *) *my_session_handle; p = (struct Curl_gsk_descriptor *) *my_session_handle;
if((rc = gsk_secure_soc_close(&p->h)) == GSK_OK) { rc = gsk_secure_soc_close(&p->h);
if(rc == GSK_OK) {
gsk_free_handle(p); gsk_free_handle(p);
*my_session_handle = (gsk_handle) NULL; *my_session_handle = (gsk_handle) NULL;
} }
@ -520,7 +535,8 @@ Curl_gsk_attribute_set_buffer_a(gsk_handle my_gsk_handle, GSK_BUF_ID bufID,
p = (struct Curl_gsk_descriptor *) my_gsk_handle; p = (struct Curl_gsk_descriptor *) my_gsk_handle;
if(!bufSize) if(!bufSize)
bufSize = strlen(buffer); bufSize = strlen(buffer);
if(!(ebcdicbuf = malloc(bufSize + 1))) ebcdicbuf = malloc(bufSize + 1);
if(!ebcdicbuf)
return GSK_INSUFFICIENT_STORAGE; return GSK_INSUFFICIENT_STORAGE;
QadrtConvertA2E(ebcdicbuf, buffer, bufSize, bufSize); QadrtConvertA2E(ebcdicbuf, buffer, bufSize, bufSize);
ebcdicbuf[bufSize] = '\0'; ebcdicbuf[bufSize] = '\0';
@ -586,9 +602,11 @@ cachestring(struct Curl_gsk_descriptor * p,
if(sp->ebcdicstr == ebcdicbuf) if(sp->ebcdicstr == ebcdicbuf)
break; break;
if(!sp) { if(!sp) {
if(!(sp = (struct gskstrlist *) malloc(sizeof *sp))) sp = (struct gskstrlist *) malloc(sizeof *sp);
if(!sp)
return GSK_INSUFFICIENT_STORAGE; return GSK_INSUFFICIENT_STORAGE;
if(!(asciibuf = malloc(bufsize + 1))) { asciibuf = malloc(bufsize + 1);
if(!asciibuf) {
free(sp); free(sp);
return GSK_INSUFFICIENT_STORAGE; return GSK_INSUFFICIENT_STORAGE;
} }
@ -619,9 +637,11 @@ Curl_gsk_attribute_get_buffer_a(gsk_handle my_gsk_handle, GSK_BUF_ID bufID,
if(!buffer || !bufSize) if(!buffer || !bufSize)
return GSK_OS400_ERROR_INVALID_POINTER; return GSK_OS400_ERROR_INVALID_POINTER;
p = (struct Curl_gsk_descriptor *) my_gsk_handle; p = (struct Curl_gsk_descriptor *) my_gsk_handle;
if((rc = gsk_attribute_get_buffer(p->h, bufID, &mybuf, &mylen)) != GSK_OK) rc = gsk_attribute_get_buffer(p->h, bufID, &mybuf, &mylen);
if(rc != GSK_OK)
return rc; return rc;
if((rc = cachestring(p, mybuf, mylen, buffer)) == GSK_OK) rc = cachestring(p, mybuf, mylen, buffer);
if(rc == GSK_OK)
*bufSize = mylen; *bufSize = mylen;
return rc; return rc;
} }
@ -756,7 +776,8 @@ Curl_gss_convert_in_place(OM_uint32 * minor_status, gss_buffer_t buf)
i = buf->length; i = buf->length;
if(i) { if(i) {
if(!(t = malloc(i))) { t = malloc(i);
if(!t) {
gss_release_buffer(minor_status, buf); gss_release_buffer(minor_status, buf);
if(minor_status) if(minor_status)
@ -789,7 +810,8 @@ Curl_gss_import_name_a(OM_uint32 * minor_status, gss_buffer_t in_name,
memcpy((char *) &in, (char *) in_name, sizeof in); memcpy((char *) &in, (char *) in_name, sizeof in);
i = in.length; i = in.length;
if(!(in.value = malloc(i + 1))) { in.value = malloc(i + 1);
if(!in.value) {
if(minor_status) if(minor_status)
*minor_status = ENOMEM; *minor_status = ENOMEM;
@ -849,12 +871,14 @@ Curl_gss_init_sec_context_a(OM_uint32 * minor_status,
gss_buffer_t inp; gss_buffer_t inp;
in.value = NULL; in.value = NULL;
inp = input_token;
if((inp = input_token)) if(inp) {
if(inp->length && inp->value) { if(inp->length && inp->value) {
i = inp->length; i = inp->length;
if(!(in.value = malloc(i + 1))) { in.value = malloc(i + 1);
if(!in.value) {
if(minor_status) if(minor_status)
*minor_status = ENOMEM; *minor_status = ENOMEM;
@ -866,6 +890,7 @@ Curl_gss_init_sec_context_a(OM_uint32 * minor_status,
in.length = i; in.length = i;
inp = ∈ inp = ∈
} }
}
rc = gss_init_sec_context(minor_status, cred_handle, context_handle, rc = gss_init_sec_context(minor_status, cred_handle, context_handle,
target_name, mech_type, req_flags, time_req, target_name, mech_type, req_flags, time_req,
@ -932,7 +957,8 @@ Curl_ldap_init_a(char * host, int port)
i = strlen(host); i = strlen(host);
if(!(ehost = malloc(i + 1))) ehost = malloc(i + 1);
if(!ehost)
return (void *) NULL; return (void *) NULL;
QadrtConvertA2E(ehost, host, i, i); QadrtConvertA2E(ehost, host, i, i);
@ -957,7 +983,8 @@ Curl_ldap_simple_bind_s_a(void * ld, char * dn, char * passwd)
if(dn) { if(dn) {
i = strlen(dn); i = strlen(dn);
if(!(edn = malloc(i + 1))) edn = malloc(i + 1);
if(!edn)
return LDAP_NO_MEMORY; return LDAP_NO_MEMORY;
QadrtConvertA2E(edn, dn, i, i); QadrtConvertA2E(edn, dn, i, i);
@ -967,7 +994,8 @@ Curl_ldap_simple_bind_s_a(void * ld, char * dn, char * passwd)
if(passwd) { if(passwd) {
i = strlen(passwd); i = strlen(passwd);
if(!(epasswd = malloc(i + 1))) { epasswd = malloc(i + 1);
if(!epasswd) {
free(edn); free(edn);
return LDAP_NO_MEMORY; return LDAP_NO_MEMORY;
} }
@ -1003,7 +1031,8 @@ Curl_ldap_search_s_a(void * ld, char * base, int scope, char * filter,
if(base) { if(base) {
i = strlen(base); i = strlen(base);
if(!(ebase = malloc(i + 1))) ebase = malloc(i + 1);
if(!ebase)
status = LDAP_NO_MEMORY; status = LDAP_NO_MEMORY;
else { else {
QadrtConvertA2E(ebase, base, i, i); QadrtConvertA2E(ebase, base, i, i);
@ -1014,7 +1043,8 @@ Curl_ldap_search_s_a(void * ld, char * base, int scope, char * filter,
if(filter && status == LDAP_SUCCESS) { if(filter && status == LDAP_SUCCESS) {
i = strlen(filter); i = strlen(filter);
if(!(efilter = malloc(i + 1))) efilter = malloc(i + 1);
if(!efilter)
status = LDAP_NO_MEMORY; status = LDAP_NO_MEMORY;
else { else {
QadrtConvertA2E(efilter, filter, i, i); QadrtConvertA2E(efilter, filter, i, i);
@ -1026,13 +1056,15 @@ Curl_ldap_search_s_a(void * ld, char * base, int scope, char * filter,
for(i = 0; attrs[i++];) for(i = 0; attrs[i++];)
; ;
if(!(eattrs = calloc(i, sizeof *eattrs))) eattrs = calloc(i, sizeof *eattrs);
if(!eattrs)
status = LDAP_NO_MEMORY; status = LDAP_NO_MEMORY;
else { else {
for(j = 0; attrs[j]; j++) { for(j = 0; attrs[j]; j++) {
i = strlen(attrs[j]); i = strlen(attrs[j]);
if(!(eattrs[j] = malloc(i + 1))) { eattrs[j] = malloc(i + 1);
if(!eattrs[j]) {
status = LDAP_NO_MEMORY; status = LDAP_NO_MEMORY;
break; break;
} }
@ -1073,7 +1105,8 @@ Curl_ldap_get_values_len_a(void * ld, LDAPMessage * entry, const char * attr)
if(attr) { if(attr) {
int i = strlen(attr); int i = strlen(attr);
if(!(cp = malloc(i + 1))) { cp = malloc(i + 1);
if(!cp) {
ldap_set_lderrno(ld, LDAP_NO_MEMORY, NULL, ldap_set_lderrno(ld, LDAP_NO_MEMORY, NULL,
ldap_err2string(LDAP_NO_MEMORY)); ldap_err2string(LDAP_NO_MEMORY));
return (struct berval * *) NULL; return (struct berval * *) NULL;
@ -1116,7 +1149,8 @@ Curl_ldap_get_dn_a(void * ld, LDAPMessage * entry)
i = strlen(cp); i = strlen(cp);
if(!(cp2 = malloc(i + 1))) cp2 = malloc(i + 1);
if(!cp2)
return cp2; return cp2;
QadrtConvertE2A(cp2, cp, i, i); QadrtConvertE2A(cp2, cp, i, i);
@ -1148,7 +1182,8 @@ Curl_ldap_first_attribute_a(void * ld,
i = strlen(cp); i = strlen(cp);
if(!(cp2 = malloc(i + 1))) cp2 = malloc(i + 1);
if(!cp2)
return cp2; return cp2;
QadrtConvertE2A(cp2, cp, i, i); QadrtConvertE2A(cp2, cp, i, i);
@ -1180,7 +1215,8 @@ Curl_ldap_next_attribute_a(void * ld,
i = strlen(cp); i = strlen(cp);
if(!(cp2 = malloc(i + 1))) cp2 = malloc(i + 1);
if(!cp2)
return cp2; return cp2;
QadrtConvertE2A(cp2, cp, i, i); QadrtConvertE2A(cp2, cp, i, i);