From 14eb9b46326f70d6c14ee82614b8107941b04dbe Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Thu, 12 Sep 2024 18:43:19 +0200 Subject: Use yy_scan_string() instead of fmemopen(); --- src/main.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index c301fdf..d4af50c 100644 --- a/src/main.c +++ b/src/main.c @@ -138,17 +138,18 @@ usage: interactive = sflag == NULL && argc == 0 && isatty(STDIN_FILENO); if (argc == 0) { - if (sflag != NULL && - (yyin = fmemopen((char *)sflag, strlen(sflag), "r")) == NULL) - { - err(1, "fmemopen"); - } - - current_file = "-"; - for (;;) { - if (yyparse() == 0) - break; - rv = EXIT_FAILURE; + if (sflag == NULL) { + current_file = "-"; + for (;;) { + if (yyparse() == 0) + break; + rv = EXIT_FAILURE; + } + } else { + current_file = "-s"; + YY_BUFFER_STATE buf = yy_scan_string(sflag); + (void)yyparse(); + yy_delete_buffer(buf); } } else for (int i = 0; i < argc; i++) { if (streq(argv[i], "-")) @@ -160,7 +161,7 @@ usage: } current_file = argv[i]; - yyparse(); + (void)yyparse(); fclose(yyin); } -- cgit v1.2.3