Skip to content

Commit 43448e8

Browse files
authored
Merge pull request #3160 from masatake/update-subtrees
Update subtrees
2 parents d6b0eda + 0e675dc commit 43448e8

File tree

11 files changed

+80
-58
lines changed

11 files changed

+80
-58
lines changed

libreadtags/.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- run:
2424
name: Test
2525
command: |
26-
make check
26+
make check VERBOSE=1
2727
fedora31_distcheck:
2828
working_directory: ~/libreadtags
2929
docker:

libreadtags/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ test-driver
3131

3232
tests/*.log
3333
tests/*.trs
34+
tests/test-api-tagsClose
3435
tests/test-api-tagsFind
3536
tests/test-api-tagsFirst
3637
tests/test-api-tagsFirstPseudoTag
3738
tests/test-api-tagsOpen
39+
tests/test-api-tagsSetSortType
3840
tests/test-fix-null-deref
3941
tests/test-fix-unescaping

libreadtags/NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Version ???
2+
3+
- delete debug output automatically printed when DEBUG is defiend in
4+
build-time.
5+
6+
- fix potential crashes trigged when passing NULL as `file` parameter
7+
to the API functions. Provided by rootkea (GitHub account).
8+
19
# Version 0.1.0
210

311
- propagate internal errors to caller

libreadtags/autogen.sh

100644100755
File mode changed.

libreadtags/readtags.c

Lines changed: 45 additions & 24 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)
1042+
return TagFailure;
1043+
1044+
if (!file->initialized || file->err)
10381045
{
10391046
file->err = TagErrnoInvalidArgument;
10401047
return TagFailure;
@@ -1095,18 +1102,12 @@ static tagResult find (tagFile *const file, tagEntry *const entry,
10951102
if ((file->sortMethod == TAG_SORTED && !file->search.ignorecase) ||
10961103
(file->sortMethod == TAG_FOLDSORTED && file->search.ignorecase))
10971104
{
1098-
#ifdef DEBUG
1099-
fputs ("<performing binary search>\n", stderr);
1100-
#endif
11011105
result = findBinary (file);
11021106
if (result == TagFailure && file->err)
11031107
return TagFailure;
11041108
}
11051109
else
11061110
{
1107-
#ifdef DEBUG
1108-
fputs ("<performing sequential search>\n", stderr);
1109-
#endif
11101111
result = findSequential (file);
11111112
if (result == TagFailure && file->err)
11121113
return TagFailure;
@@ -1155,9 +1156,12 @@ static tagResult findNext (tagFile *const file, tagEntry *const entry)
11551156

11561157
static tagResult findPseudoTag (tagFile *const file, int rewindBeforeFinding, tagEntry *const entry)
11571158
{
1158-
if (file == NULL || (!file->initialized) || file->err)
1159+
if (file == NULL)
1160+
return TagFailure;
1161+
1162+
if (!file->initialized || file->err)
11591163
{
1160-
file->err= TagErrnoInvalidArgument;;
1164+
file->err = TagErrnoInvalidArgument;
11611165
return TagFailure;
11621166
}
11631167

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

11891193
extern tagResult tagsSetSortType (tagFile *const file, const tagSortType type)
11901194
{
1191-
if (file == NULL || (!file->initialized) || file->err)
1195+
if (file == NULL)
1196+
return TagFailure;
1197+
1198+
if (!file->initialized || file->err)
11921199
{
11931200
file->err = TagErrnoInvalidArgument;
11941201
return TagFailure;
@@ -1209,7 +1216,10 @@ extern tagResult tagsSetSortType (tagFile *const file, const tagSortType type)
12091216

12101217
extern tagResult tagsFirst (tagFile *const file, tagEntry *const entry)
12111218
{
1212-
if (file == NULL || (!file->initialized) || file->err)
1219+
if (file == NULL)
1220+
return TagFailure;
1221+
1222+
if (!file->initialized || file->err)
12131223
{
12141224
file->err = TagErrnoInvalidArgument;
12151225
return TagFailure;
@@ -1222,7 +1232,10 @@ extern tagResult tagsFirst (tagFile *const file, tagEntry *const entry)
12221232

12231233
extern tagResult tagsNext (tagFile *const file, tagEntry *const entry)
12241234
{
1225-
if (file == NULL || (!file->initialized) || file->err)
1235+
if (file == NULL)
1236+
return TagFailure;
1237+
1238+
if (!file->initialized || file->err)
12261239
{
12271240
file->err = TagErrnoInvalidArgument;
12281241
return TagFailure;
@@ -1242,21 +1255,29 @@ extern const char *tagsField (const tagEntry *const entry, const char *const key
12421255
extern tagResult tagsFind (tagFile *const file, tagEntry *const entry,
12431256
const char *const name, const int options)
12441257
{
1245-
if (file == NULL || !file->initialized || file->err)
1258+
if (file == NULL)
1259+
return TagFailure;
1260+
1261+
if (!file->initialized || file->err)
12461262
{
12471263
file->err = TagErrnoInvalidArgument;
12481264
return TagFailure;
12491265
}
1266+
12501267
return find (file, entry, name, options);
12511268
}
12521269

12531270
extern tagResult tagsFindNext (tagFile *const file, tagEntry *const entry)
12541271
{
1255-
if (file == NULL || !file->initialized || file->err)
1272+
if (file == NULL)
1273+
return TagFailure;
1274+
1275+
if (!file->initialized || file->err)
12561276
{
12571277
file->err = TagErrnoInvalidArgument;
12581278
return TagFailure;
12591279
}
1280+
12601281
return findNext (file, entry);
12611282
}
12621283

libreadtags/tests/test-api-tagsFind.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ check_finding0 (tagFile *t, const char *name, const int options,
6565
if (err == x->err)
6666
{
6767
if (err == 0)
68-
fprintf (stderr, "not found, and it is expected\n", err);
68+
fprintf (stderr, "not found, and it is expected\n");
6969
else
7070
fprintf (stderr, "error as expected: %d\n", err);
7171
continue;
7272
}
7373
else
7474
{
75-
fprintf (stderr, "errer number doesn't match: %d (expected: %d)\n",
75+
fprintf (stderr, "error number doesn't match: %d (expected: %d)\n",
7676
err, x->err);
7777
return 1;
7878
}

libreadtags/tests/test-api-tagsOpen.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ main (void)
157157
}
158158
fprintf (stderr, "ok\n");
159159

160-
fprintf (stderr, "opening a / (EISDIR is expected)...");
160+
fprintf (stderr, "opening a / (an error is expected)...");
161+
info.status.error_number = 0;
161162
t = tagsOpen ("/", &info);
162163
if (t != NULL)
163164
{
@@ -169,12 +170,12 @@ main (void)
169170
fprintf (stderr, "unexpected result (opened != 0)\n");
170171
return 1;
171172
}
172-
else if (info.status.error_number != EISDIR)
173+
else if (info.status.error_number == 0)
173174
{
174-
fprintf (stderr, "unexpected result (error_number != EISDIR)\n");
175+
fprintf (stderr, "no error\n");
175176
return 1;
176177
}
177-
fprintf (stderr, "ok\n");
178+
fprintf (stderr, "ok (errno: %d)\n", info.status.error_number);
178179

179180
fprintf (stderr, "closing the unopened tag file...");
180181
if (tagsClose (t) == TagSuccess)
@@ -275,9 +276,9 @@ main (void)
275276
for (int i = 0; i < 6; i++)
276277
{
277278
char tagf_name_tmpl [] = "./api-tagsOpen-incomplete-program-author-%d.tags";
278-
char tagf_name [sizeof (tagf_name_tmpl)];
279+
char tagf_name [sizeof (tagf_name_tmpl) - 1];
279280
fprintf (stderr, "opening a tags file with incomplete PROGRAM_AUTHOR field [trimming level: %d]...", i);
280-
sprintf (tagf_name, tagf_name_tmpl, i);
281+
snprintf (tagf_name, sizeof (tagf_name), tagf_name_tmpl, i);
281282
t = tagsOpen (tagf_name, &info);
282283
if (t == NULL)
283284
{

libreadtags/tests/test-fix-null-deref.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ main (void)
4141
fprintf (stderr, "ok\n");
4242

4343
tagEntry e;
44-
tagResult r;
4544

4645
/* Without fix, this program crashes in tagsFirst(). */
4746
tagsFirst (t, &e);

misc/packcc/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Some macros are prepared to customize the parser. The macro definition should be
339339

340340
```
341341
%source {
342-
#define PCC_GETCHAR(auxil) get_character(auxil->input)
342+
#define PCC_GETCHAR(auxil) get_character((auxil)->input)
343343
#define PCC_BUFFERSIZE 1024
344344
}
345345
```
@@ -430,8 +430,7 @@ A very simple implementation could look like this:
430430
```C
431431
static const char *dbg_str[] = { "Evaluating rule", "Matched rule", "Abandoning rule" };
432432
#define PCC_DEBUG(event, rule, level, pos, buffer, length) \
433-
fprintf(stderr, "%*s%s %s @%d [%.*s]\n", level * 2, "", dbg_str[event], rule, pos, length, buffer)
434-
}
433+
fprintf(stderr, "%*s%s %s @%zu [%.*s]\n", (int)((level) * 2), "", dbg_str[event], rule, pos, (int)(length), buffer)
435434
```
436435

437436
The default is to do nothing:

misc/packcc/src/packcc.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ static size_t strnlen_(const char *str, size_t maxlen) {
6464
#include <unistd.h> /* for unlink() */
6565
#endif
6666

67-
#ifndef __attribute__
67+
#ifndef __has_attribute
6868
#define __attribute__(x)
6969
#endif
7070

7171
#undef TRUE /* to avoid macro definition conflicts with the system header file of IBM AIX */
7272
#undef FALSE
7373

74-
#define VERSION "1.5.0"
74+
#define VERSION "1.5.1"
7575

7676
#ifndef BUFFER_INIT_SIZE
7777
#define BUFFER_INIT_SIZE 256
@@ -285,7 +285,8 @@ typedef enum code_reach_tag {
285285

286286
static const char *g_cmdname = "packcc"; /* replaced later with actual one */
287287

288-
static int print_error(const char *format, ...) __attribute__((format(printf, 1, 2))) {
288+
__attribute__((format(printf, 1, 2)))
289+
static int print_error(const char *format, ...) {
289290
int n;
290291
va_list a;
291292
va_start(a, format);
@@ -352,7 +353,8 @@ static int fputs_e(const char *s, FILE *stream) {
352353
return r;
353354
}
354355

355-
static int fprintf_e(FILE *stream, const char *format, ...) __attribute__((format(printf, 2, 3))) {
356+
__attribute__((format(printf, 2, 3)))
357+
static int fprintf_e(FILE *stream, const char *format, ...) {
356358
int n;
357359
va_list a;
358360
va_start(a, format);
@@ -1436,8 +1438,8 @@ static void verify_captures(context_t *ctx, node_t *node, node_const_array_t *ca
14361438
if (node->data.expand.index == capts->buf[i]->data.capture.index) break;
14371439
}
14381440
if (i >= capts->len && node->data.expand.index != VOID_VALUE) {
1439-
print_error("%s:" FMT_LU ":" FMT_LU ": Capture %d not available at this position\n",
1440-
ctx->iname, (ulong_t)(node->data.expand.line + 1), (ulong_t)(node->data.expand.col + 1), node->data.expand.index + 1);
1441+
print_error("%s:" FMT_LU ":" FMT_LU ": Capture " FMT_LU " not available at this position\n",
1442+
ctx->iname, (ulong_t)(node->data.expand.line + 1), (ulong_t)(node->data.expand.col + 1), (ulong_t)(node->data.expand.index + 1));
14411443
ctx->errnum++;
14421444
}
14431445
}
@@ -2730,26 +2732,20 @@ static code_reach_t generate_predicating_code(generate_t *gen, const node_t *exp
27302732
}
27312733
write_characters(gen->stream, ' ', indent);
27322734
fputs_e("const size_t p = ctx->cur;\n", gen->stream);
2733-
write_characters(gen->stream, ' ', indent);
2734-
fputs_e("const size_t n = chunk->thunks.len;\n", gen->stream);
27352735
if (neg) {
27362736
const int l = ++gen->label;
27372737
r = generate_code(gen, expr, l, indent, FALSE);
27382738
if (r != CODE_REACH__ALWAYS_FAIL) {
27392739
write_characters(gen->stream, ' ', indent);
27402740
fputs_e("ctx->cur = p;\n", gen->stream);
27412741
write_characters(gen->stream, ' ', indent);
2742-
fputs_e("pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);\n", gen->stream);
2743-
write_characters(gen->stream, ' ', indent);
27442742
fprintf_e(gen->stream, "goto L%04d;\n", onfail);
27452743
}
27462744
if (r != CODE_REACH__ALWAYS_SUCCEED) {
27472745
if (indent > 4) write_characters(gen->stream, ' ', indent - 4);
27482746
fprintf_e(gen->stream, "L%04d:;\n", l);
27492747
write_characters(gen->stream, ' ', indent);
27502748
fputs_e("ctx->cur = p;\n", gen->stream);
2751-
write_characters(gen->stream, ' ', indent);
2752-
fputs_e("pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);\n", gen->stream);
27532749
}
27542750
switch (r) {
27552751
case CODE_REACH__ALWAYS_SUCCEED: r = CODE_REACH__ALWAYS_FAIL; break;
@@ -2764,8 +2760,6 @@ static code_reach_t generate_predicating_code(generate_t *gen, const node_t *exp
27642760
if (r != CODE_REACH__ALWAYS_FAIL) {
27652761
write_characters(gen->stream, ' ', indent);
27662762
fputs_e("ctx->cur = p;\n", gen->stream);
2767-
write_characters(gen->stream, ' ', indent);
2768-
fputs_e("pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);\n", gen->stream);
27692763
}
27702764
if (r == CODE_REACH__BOTH) {
27712765
write_characters(gen->stream, ' ', indent);
@@ -2777,8 +2771,6 @@ static code_reach_t generate_predicating_code(generate_t *gen, const node_t *exp
27772771
write_characters(gen->stream, ' ', indent);
27782772
fputs_e("ctx->cur = p;\n", gen->stream);
27792773
write_characters(gen->stream, ' ', indent);
2780-
fputs_e("pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);\n", gen->stream);
2781-
write_characters(gen->stream, ' ', indent);
27822774
fprintf_e(gen->stream, "goto L%04d;\n", onfail);
27832775
}
27842776
if (r == CODE_REACH__BOTH) {
@@ -4283,8 +4275,8 @@ static bool_t generate(context_t *ctx) {
42834275
}
42844276
fprintf_e(
42854277
sstream,
4286-
"static void pcc_action_%s_%d(%s_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {\n",
4287-
r->name, d, get_prefix(ctx)
4278+
"static void pcc_action_%s_" FMT_LU "(%s_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {\n",
4279+
r->name, (ulong_t)d, get_prefix(ctx)
42884280
);
42894281
fputs_e(
42904282
"#define auxil (__pcc_ctx->auxil)\n"
@@ -4303,8 +4295,8 @@ static bool_t generate(context_t *ctx) {
43034295
}
43044296
fputs_e(
43054297
"#define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)\n"
4306-
"#define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)\n"
4307-
"#define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)\n",
4298+
"#define _0s ((const size_t)(__pcc_ctx->pos + __pcc_in->data.leaf.capt0.range.start))\n"
4299+
"#define _0e ((const size_t)(__pcc_ctx->pos + __pcc_in->data.leaf.capt0.range.end))\n",
43084300
sstream
43094301
);
43104302
k = 0;

0 commit comments

Comments
 (0)