From bda3c885596c445a3f181c3935eabd953b455486 Mon Sep 17 00:00:00 2001 From: "Roberto E. Vargas Caballero" Date: Sun, 23 Nov 2025 12:31:30 +0100 Subject: [PATCH] bc: Fix comment parsing The function comment was misparsing comments, because it ate always the character after a *, invalidating sequences like **/. Also, as it didn't count new line characters error messages were misleading. --- bc.y | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bc.y b/bc.y index 37f33e7..6f6b52d 100644 --- a/bc.y +++ b/bc.y @@ -587,10 +587,17 @@ operand(int ch) static void comment(void) { - do { - while (getchar() != '*') - ; - } while (getchar() != '/'); + int c; + + for (;;) { + while ((c = getchar()) != '*') { + if (c == '\n') + lineno++; + } + if ((c = getchar()) == '/') + break; + ungetc(c, stdin); + } } static int