[PATCH v2 16/21] libtracefs: Add error message when calculation has no label

From: Steven Rostedt
Date: Tue Aug 03 2021 - 00:26:44 EST


From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx>

If a calculation between event fields is performed and there's no label
(name) for it, it errors out, causing the bison parser to give a strange
error:

FAILED MEMORY: add_selection(sb, (yyvsp[0].expr), NULL)
Failed creating synthetic event!: No such file or directory

Instead, just set the compare->name field to NULL, and report a better
error later on in the processing.

ERROR: 'no name'
Field calculations must be labeled 'AS name'

Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
---
src/tracefs-sqlhist.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/tracefs-sqlhist.c b/src/tracefs-sqlhist.c
index f191661610c9..c27f7478a527 100644
--- a/src/tracefs-sqlhist.c
+++ b/src/tracefs-sqlhist.c
@@ -242,8 +242,6 @@ __hidden int add_selection(struct sqlhist_bison *sb, void *select,
case EXPR_FIELD:
break;
case EXPR_COMPARE:
- if (!name)
- return -1;
expr->compare.name = name;
break;
case EXPR_NUMBER:
@@ -692,6 +690,9 @@ static int build_compare(struct tracefs_synth *synth,
enum tracefs_synth_calc calc;
int ret;

+ if (!compare->name)
+ return -1;
+
lval = &compare->lval->field;
rval = &compare->rval->field;

@@ -1069,6 +1070,14 @@ static void compare_error(struct tep_handle *tep,
{
struct compare *compare = &expr->compare;

+ if (!compare->name) {
+ sb->line_no = expr->line;
+ sb->line_idx = expr->idx + strlen("no name");
+
+ parse_error(sb, "no name",
+ "Field calculations must be labeled 'AS name'\n");
+ }
+
switch (errno) {
case ENODEV:
case EBADE:
--
2.30.2