Thread (26 messages) flat view 26 messages, 4 authors, 2021-08-04
STALE1835d

Revision v2 of 3 in this series.

Revisions (3)
  1. v1 [diff vs current]
  2. v2 current
  3. v3 [diff vs current]

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

From: Steven Rostedt <rostedt@goodmis.org>
Date: 2021-08-03 04:26:43
Also in: lkml
Subsystem: the rest · Maintainer: Linus Torvalds

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

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@goodmis.org>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help