[hackers] [sbase] bc: Fix comment parsing || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Sun, 23 Nov 2025 12:34:35 +0100 (CET)

commit bda3c885596c445a3f181c3935eabd953b455486
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.net>
AuthorDate: Sun Nov 23 12:31:30 2025 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.net>
CommitDate: Sun Nov 23 12:31:30 2025 +0100

    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.

diff --git a/bc.y b/bc.y
index 37f33e7..6f6b52d 100644
--- a/bc.y
+++ b/bc.y
_AT_@ -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
Received on Sun Nov 23 2025 - 12:34:35 CET

This archive was generated by hypermail 2.3.0 : Sun Nov 23 2025 - 12:36:36 CET