Skip to content

Commit 254702d

Browse files
committed
Access file->err only if file is not NULL
Found by: scan-build
1 parent 6c0df5b commit 254702d

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed

readtags.c

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -870,19 +870,23 @@ static void terminate (tagFile *const file)
870870
static tagResult readNext (tagFile *const file, tagEntry *const entry)
871871
{
872872
tagResult result;
873-
if (file == NULL || ! file->initialized)
873+
874+
if (file == NULL)
875+
return TagFailure;
876+
877+
if (! file->initialized)
874878
{
875879
file->err = TagErrnoInvalidArgument;
876-
result = TagFailure;
877-
}
878-
else if (! readTagLine (file, &file->err))
879-
result = TagFailure;
880-
else
881-
{
882-
result = (entry != NULL)
883-
? parseTagLine (file, entry, &file->err)
884-
: TagSuccess;
880+
return TagFailure;
885881
}
882+
883+
if (! readTagLine (file, &file->err))
884+
return TagFailure;
885+
886+
result = (entry != NULL)
887+
? parseTagLine (file, entry, &file->err)
888+
: TagSuccess;
889+
886890
return result;
887891
}
888892

@@ -1034,7 +1038,10 @@ static tagResult findSequentialFull (tagFile *const file,
10341038
int (* isAcceptable) (tagFile *const, void *),
10351039
void *data)
10361040
{
1037-
if (file == NULL || !file->initialized || file->err)
1041+
if (file == NULL || file->err)
1042+
return TagFailure;
1043+
1044+
if (!file->initialized)
10381045
{
10391046
file->err = TagErrnoInvalidArgument;
10401047
return TagFailure;
@@ -1149,9 +1156,12 @@ static tagResult findNext (tagFile *const file, tagEntry *const entry)
11491156

11501157
static tagResult findPseudoTag (tagFile *const file, int rewindBeforeFinding, tagEntry *const entry)
11511158
{
1152-
if (file == NULL || (!file->initialized) || file->err)
1159+
if (file == NULL || file->err)
1160+
return TagFailure;
1161+
1162+
if (!file->initialized)
11531163
{
1154-
file->err= TagErrnoInvalidArgument;;
1164+
file->err = TagErrnoInvalidArgument;
11551165
return TagFailure;
11561166
}
11571167

@@ -1182,7 +1192,10 @@ extern tagFile *tagsOpen (const char *const filePath, tagFileInfo *const info)
11821192

11831193
extern tagResult tagsSetSortType (tagFile *const file, const tagSortType type)
11841194
{
1185-
if (file == NULL || (!file->initialized) || file->err)
1195+
if (file == NULL || file->err)
1196+
return TagFailure;
1197+
1198+
if (!file->initialized)
11861199
{
11871200
file->err = TagErrnoInvalidArgument;
11881201
return TagFailure;
@@ -1203,7 +1216,10 @@ extern tagResult tagsSetSortType (tagFile *const file, const tagSortType type)
12031216

12041217
extern tagResult tagsFirst (tagFile *const file, tagEntry *const entry)
12051218
{
1206-
if (file == NULL || (!file->initialized) || file->err)
1219+
if (file == NULL || file->err)
1220+
return TagFailure;
1221+
1222+
if (!file->initialized)
12071223
{
12081224
file->err = TagErrnoInvalidArgument;
12091225
return TagFailure;
@@ -1216,7 +1232,10 @@ extern tagResult tagsFirst (tagFile *const file, tagEntry *const entry)
12161232

12171233
extern tagResult tagsNext (tagFile *const file, tagEntry *const entry)
12181234
{
1219-
if (file == NULL || (!file->initialized) || file->err)
1235+
if (file == NULL || file->err)
1236+
return TagFailure;
1237+
1238+
if (!file->initialized)
12201239
{
12211240
file->err = TagErrnoInvalidArgument;
12221241
return TagFailure;
@@ -1236,21 +1255,29 @@ extern const char *tagsField (const tagEntry *const entry, const char *const key
12361255
extern tagResult tagsFind (tagFile *const file, tagEntry *const entry,
12371256
const char *const name, const int options)
12381257
{
1239-
if (file == NULL || !file->initialized || file->err)
1258+
if (file == NULL || file->err)
1259+
return TagFailure;
1260+
1261+
if (!file->initialized)
12401262
{
12411263
file->err = TagErrnoInvalidArgument;
12421264
return TagFailure;
12431265
}
1266+
12441267
return find (file, entry, name, options);
12451268
}
12461269

12471270
extern tagResult tagsFindNext (tagFile *const file, tagEntry *const entry)
12481271
{
1249-
if (file == NULL || !file->initialized || file->err)
1272+
if (file == NULL || file->err)
1273+
return TagFailure;
1274+
1275+
if (!file->initialized)
12501276
{
12511277
file->err = TagErrnoInvalidArgument;
12521278
return TagFailure;
12531279
}
1280+
12541281
return findNext (file, entry);
12551282
}
12561283

0 commit comments

Comments
 (0)