mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-23 17:33:50 +03:00
clang-tidy: move assignments out of if
Found with bugprone-assignment-in-if-condition Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
parent
5803ad26b5
commit
2def7b4b28
@ -959,9 +959,11 @@ xmlLoadFileContent(const char *filename)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STAT
|
||||
if ((fd = open(filename, O_RDONLY)) < 0)
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd < 0)
|
||||
#else
|
||||
if ((fd = fopen(filename, "rb")) == NULL)
|
||||
fd = fopen(filename, "rb");
|
||||
if (fd == NULL)
|
||||
#endif
|
||||
{
|
||||
return (NULL);
|
||||
|
@ -377,7 +377,8 @@ UTF8Toisolat1(unsigned char* out, int *outlen,
|
||||
for ( ; trailing; trailing--) {
|
||||
if (in >= inend)
|
||||
break;
|
||||
if (((d= *in++) & 0xC0) != 0x80) {
|
||||
d = *in++;
|
||||
if ((d & 0xC0) != 0x80) {
|
||||
*outlen = out - outstart;
|
||||
*inlen = processed - instart;
|
||||
return(XML_ENC_ERR_INPUT);
|
||||
|
15
list.c
15
list.c
@ -188,13 +188,15 @@ xmlListPtr
|
||||
xmlListCreate(xmlListDeallocator deallocator, xmlListDataCompare compare)
|
||||
{
|
||||
xmlListPtr l;
|
||||
if (NULL == (l = (xmlListPtr )xmlMalloc( sizeof(xmlList))))
|
||||
l = (xmlListPtr)xmlMalloc(sizeof(xmlList));
|
||||
if (l == NULL)
|
||||
return (NULL);
|
||||
/* Initialize the list to NULL */
|
||||
memset(l, 0, sizeof(xmlList));
|
||||
|
||||
/* Add the sentinel */
|
||||
if (NULL ==(l->sentinel = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink)))) {
|
||||
l->sentinel = (xmlLinkPtr)xmlMalloc(sizeof(xmlLink));
|
||||
if (l->sentinel == NULL) {
|
||||
xmlFree(l);
|
||||
return (NULL);
|
||||
}
|
||||
@ -565,7 +567,8 @@ xmlListPushBack(xmlListPtr l, void *data)
|
||||
return(0);
|
||||
lkPlace = l->sentinel->prev;
|
||||
/* Add the new link */
|
||||
if (NULL ==(lkNew = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink))))
|
||||
lkNew = (xmlLinkPtr)xmlMalloc(sizeof(xmlLink));
|
||||
if (lkNew == NULL)
|
||||
return (0);
|
||||
lkNew->data = data;
|
||||
lkNew->next = lkPlace->next;
|
||||
@ -638,7 +641,8 @@ xmlListSort(xmlListPtr l)
|
||||
* an insert. This is slow...
|
||||
*/
|
||||
|
||||
if (NULL ==(lTemp = xmlListDup(l)))
|
||||
lTemp = xmlListDup(l);
|
||||
if (lTemp == NULL)
|
||||
return;
|
||||
xmlListClear(l);
|
||||
xmlListMerge(l, lTemp);
|
||||
@ -723,7 +727,8 @@ xmlListDup(xmlListPtr old)
|
||||
* set it to be the old list for the time being whilst I work out
|
||||
* the answer
|
||||
*/
|
||||
if (NULL ==(cur = xmlListCreate(NULL, old->linkCompare)))
|
||||
cur = xmlListCreate(NULL, old->linkCompare);
|
||||
if (cur == NULL)
|
||||
return (NULL);
|
||||
if (0 != xmlListCopy(cur, old))
|
||||
return NULL;
|
||||
|
@ -480,7 +480,8 @@ static int loadMem(const char *filename, const char **mem, int *size) {
|
||||
base = malloc(info.st_size + 1);
|
||||
if (base == NULL)
|
||||
return(-1);
|
||||
if ((fd = open(filename, RD_FLAGS)) < 0) {
|
||||
fd = open(filename, RD_FLAGS);
|
||||
if (fd < 0) {
|
||||
free(base);
|
||||
return(-1);
|
||||
}
|
||||
|
@ -92,7 +92,8 @@ xmlNewMutex(void)
|
||||
{
|
||||
xmlMutexPtr tok;
|
||||
|
||||
if ((tok = malloc(sizeof(xmlMutex))) == NULL)
|
||||
tok = malloc(sizeof(xmlMutex));
|
||||
if (tok == NULL)
|
||||
return (NULL);
|
||||
xmlInitMutex(tok);
|
||||
return (tok);
|
||||
@ -188,7 +189,8 @@ xmlNewRMutex(void)
|
||||
{
|
||||
xmlRMutexPtr tok;
|
||||
|
||||
if ((tok = malloc(sizeof(xmlRMutex))) == NULL)
|
||||
tok = malloc(sizeof(xmlRMutex));
|
||||
if (tok == NULL)
|
||||
return (NULL);
|
||||
#ifdef HAVE_POSIX_THREADS
|
||||
pthread_mutex_init(&tok->lock, NULL);
|
||||
|
9
valid.c
9
valid.c
@ -673,7 +673,8 @@ done:
|
||||
xmlValidCtxtPtr xmlNewValidCtxt(void) {
|
||||
xmlValidCtxtPtr ret;
|
||||
|
||||
if ((ret = xmlMalloc(sizeof (xmlValidCtxt))) == NULL)
|
||||
ret = xmlMalloc(sizeof (xmlValidCtxt));
|
||||
if (ret == NULL)
|
||||
return (NULL);
|
||||
|
||||
(void) memset(ret, 0, sizeof (xmlValidCtxt));
|
||||
@ -2752,10 +2753,12 @@ xmlAddRef(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value,
|
||||
* Return the ref
|
||||
*/
|
||||
|
||||
if (NULL == (ref_list = xmlHashLookup(table, value))) {
|
||||
ref_list = xmlHashLookup(table, value);
|
||||
if (ref_list == NULL) {
|
||||
int res;
|
||||
|
||||
if (NULL == (ref_list = xmlListCreate(xmlFreeRef, xmlDummyCompare)))
|
||||
ref_list = xmlListCreate(xmlFreeRef, xmlDummyCompare);
|
||||
if (ref_list == NULL)
|
||||
goto failed;
|
||||
res = xmlHashAdd(table, value, ref_list);
|
||||
if (res <= 0) {
|
||||
|
15
xmllint.c
15
xmllint.c
@ -1594,7 +1594,8 @@ static void streamFile(const char *filename) {
|
||||
if (memory) {
|
||||
if (stat(filename, &info) < 0)
|
||||
return;
|
||||
if ((fd = open(filename, O_RDONLY)) < 0)
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return;
|
||||
base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
|
||||
if (base == (void *) MAP_FAILED) {
|
||||
@ -2017,7 +2018,8 @@ parseFile(const char *filename, xmlParserCtxtPtr rectxt) {
|
||||
const char *base;
|
||||
if (stat(filename, &info) < 0)
|
||||
return(NULL);
|
||||
if ((fd = open(filename, O_RDONLY)) < 0)
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return(NULL);
|
||||
base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
|
||||
if (base == (void *) MAP_FAILED) {
|
||||
@ -2147,7 +2149,8 @@ parseFile(const char *filename, xmlParserCtxtPtr rectxt) {
|
||||
|
||||
if (stat(filename, &info) < 0)
|
||||
goto error;
|
||||
if ((fd = open(filename, O_RDONLY)) < 0)
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd < 0)
|
||||
goto error;
|
||||
base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ;
|
||||
if (base == (void *) MAP_FAILED) {
|
||||
@ -2528,7 +2531,8 @@ parseAndPrintFile(const char *filename, xmlParserCtxtPtr rectxt) {
|
||||
} else {
|
||||
xmlValidCtxtPtr cvp;
|
||||
|
||||
if ((cvp = xmlNewValidCtxt()) == NULL) {
|
||||
cvp = xmlNewValidCtxt();
|
||||
if (cvp == NULL) {
|
||||
fprintf(ERR_STREAM,
|
||||
"Couldn't allocate validation context\n");
|
||||
progresult = XMLLINT_ERR_MEM;
|
||||
@ -2559,7 +2563,8 @@ parseAndPrintFile(const char *filename, xmlParserCtxtPtr rectxt) {
|
||||
} else if (postvalid) {
|
||||
xmlValidCtxtPtr cvp;
|
||||
|
||||
if ((cvp = xmlNewValidCtxt()) == NULL) {
|
||||
cvp = xmlNewValidCtxt();
|
||||
if (cvp == NULL) {
|
||||
fprintf(ERR_STREAM,
|
||||
"Couldn't allocate validation context\n");
|
||||
progresult = XMLLINT_ERR_MEM;
|
||||
|
@ -2675,7 +2675,8 @@ xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr,
|
||||
}
|
||||
}
|
||||
|
||||
if ((out_buff = xmlAllocOutputBuffer(conv_hdlr)) == NULL ) {
|
||||
out_buff = xmlAllocOutputBuffer(conv_hdlr);
|
||||
if (out_buff == NULL ) {
|
||||
xmlSaveErrMemory(NULL);
|
||||
xmlCharEncCloseFunc(conv_hdlr);
|
||||
return;
|
||||
|
@ -994,7 +994,8 @@ xmlUTF8Strsize(const xmlChar *utf, int len) {
|
||||
while ( len-- > 0) {
|
||||
if ( !*ptr )
|
||||
break;
|
||||
if ( (ch = *ptr++) & 0x80)
|
||||
ch = *ptr++;
|
||||
if ((ch & 0x80))
|
||||
while ((ch<<=1) & 0x80 ) {
|
||||
if (*ptr == 0) break;
|
||||
ptr++;
|
||||
@ -1048,7 +1049,9 @@ xmlUTF8Strpos(const xmlChar *utf, int pos) {
|
||||
if (pos < 0)
|
||||
return(NULL);
|
||||
while (pos--) {
|
||||
if ((ch=*utf++) == 0) return(NULL);
|
||||
ch = *utf++;
|
||||
if (ch == 0)
|
||||
return(NULL);
|
||||
if ( ch & 0x80 ) {
|
||||
/* if not simple ascii, verify proper format */
|
||||
if ( (ch & 0xc0) != 0xc0 )
|
||||
|
@ -954,7 +954,8 @@ static xmlIntFunc
|
||||
sptr = tptr->table;
|
||||
while (low <= high) {
|
||||
mid = (low + high) / 2;
|
||||
if ((cmp=strcmp(tname, sptr[mid].rangename)) == 0)
|
||||
cmp = strcmp(tname, sptr[mid].rangename);
|
||||
if (cmp == 0)
|
||||
return (sptr[mid].func);
|
||||
if (cmp < 0)
|
||||
high = mid - 1;
|
||||
|
@ -4439,7 +4439,8 @@ xmlTextWriterWriteDocCallback(void *context, const char *str, int len)
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context;
|
||||
int rc;
|
||||
|
||||
if ((rc = xmlParseChunk(ctxt, str, len, 0)) != 0) {
|
||||
rc = xmlParseChunk(ctxt, str, len, 0);
|
||||
if (rc != 0) {
|
||||
xmlWriterErrMsgInt(NULL, XML_ERR_INTERNAL_ERROR,
|
||||
"xmlTextWriterWriteDocCallback : XML error %d !\n",
|
||||
rc);
|
||||
@ -4463,7 +4464,8 @@ xmlTextWriterCloseDocCallback(void *context)
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context;
|
||||
int rc;
|
||||
|
||||
if ((rc = xmlParseChunk(ctxt, NULL, 0, 1)) != 0) {
|
||||
rc = xmlParseChunk(ctxt, NULL, 0, 1);
|
||||
if (rc != 0) {
|
||||
xmlWriterErrMsgInt(NULL, XML_ERR_INTERNAL_ERROR,
|
||||
"xmlTextWriterCloseDocCallback : XML error %d !\n",
|
||||
rc);
|
||||
|
4
xzlib.c
4
xzlib.c
@ -101,8 +101,8 @@ xz_error(xz_statep state, int err, const char *msg)
|
||||
}
|
||||
|
||||
/* construct error message with path */
|
||||
if ((state->msg =
|
||||
xmlMalloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
|
||||
state->msg = xmlMalloc(strlen(state->path) + strlen(msg) + 3);
|
||||
if (state->msg == NULL) {
|
||||
state->err = LZMA_MEM_ERROR;
|
||||
state->msg = (char *) "out of memory";
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user