summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-09-30 14:27:37 +0200
committerRan Benita <ran234@gmail.com>2012-09-30 15:25:56 +0200
commit26e685daaeeaa5fc1ac4166b2c066ed6fb4db930 (patch)
tree50a43833b5bab4c2ff388d8e84348abb14192c42 /src
parentee4ab30ea2a9fd7c8455b44af68007c2908a8d68 (diff)
scanner: don't strdup the file name
We don't modify it and there's no way to modify the original in the scanner_extra life time. Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/xkbcomp/scanner.l16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/xkbcomp/scanner.l b/src/xkbcomp/scanner.l
index 2f0c400..570e0bd 100644
--- a/src/xkbcomp/scanner.l
+++ b/src/xkbcomp/scanner.l
@@ -32,7 +32,7 @@
struct scanner_extra {
struct xkb_context *ctx;
- char *scanFile;
+ const char *file_name;
char scanBuf[1024];
char *s;
};
@@ -210,7 +210,7 @@ scanner_error_extra(struct YYLTYPE *loc, struct scanner_extra *extra,
{
log_err(extra->ctx, "%s: line %d of %s\n", msg,
loc->first_line,
- extra->scanFile ? extra->scanFile : "(unknown)");
+ extra->file_name ? extra->file_name : "(unknown)");
}
void
@@ -270,18 +270,14 @@ init_scanner(yyscan_t *scanner, struct scanner_extra *extra,
return false;
extra->ctx = ctx;
-
- extra->scanFile = strdup(file_name);
- if (!extra->scanFile)
- return false;
+ extra->file_name = file_name;
return true;
}
static void
-clear_scanner(yyscan_t scanner, struct scanner_extra *extra)
+clear_scanner(yyscan_t scanner)
{
- free(extra->scanFile);
yylex_destroy(scanner);
}
@@ -302,7 +298,7 @@ XkbParseString(struct xkb_context *ctx, const char *string,
xkb_file = parse(ctx, scanner);
yy_delete_buffer(state, scanner);
- clear_scanner(scanner, &extra);
+ clear_scanner(scanner);
return xkb_file;
}
@@ -324,7 +320,7 @@ XkbParseFile(struct xkb_context *ctx, FILE *file, const char *file_name)
xkb_file = parse(ctx, scanner);
yy_delete_buffer(state, scanner);
- clear_scanner(scanner, &extra);
+ clear_scanner(scanner);
return xkb_file;
}