From 36c91405feb65a1e6ca044c4a3a8ac485b3ba5f2 Mon Sep 17 00:00:00 2001
From: Sahil Sharma <ssharma32181@gmail.com>
Date: Tue, 14 Apr 2026 00:10:45 +0530
Subject: [PATCH] grep: improve error message for invalid pattern * src/grep.c:
 Update error message for clarity.

---
 src/grep.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/grep.c b/src/grep.c
index ba7c963..1570a63 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -227,6 +227,7 @@ pattern_file_name (idx_t lineno, idx_t *new_lineno)
 static void const *poison_buf;
 static idx_t poison_len;
 
+/* Unpoison the memory region and reset poison_buf and poison_len.  */
 static void
 clear_asan_poison (void)
 {
@@ -234,6 +235,7 @@ clear_asan_poison (void)
     __asan_unpoison_memory_region (poison_buf, poison_len);
 }
 
+/* Poison the memory region starting at ADDR with size SIZE.  */
 static void
 asan_poison (void const *addr, idx_t size)
 {
@@ -366,24 +368,28 @@ static const char *sgr_start = "\33[%sm\33[K";
 static const char *sgr_end   = "\33[m\33[K";
 
 /* SGR utility functions.  */
+/* Start a colorized output item with color string S.  */
 static void
 pr_sgr_start (char const *s)
 {
   if (*s)
     print_start_colorize (sgr_start, s);
 }
+/* End a colorized output item with color string S.  */
 static void
 pr_sgr_end (char const *s)
 {
   if (*s)
     print_end_colorize (sgr_end);
 }
+/* Start colorized output if color_option is enabled.  */
 static void
 pr_sgr_start_if (char const *s)
 {
   if (color_option)
     pr_sgr_start (s);
 }
+/* End colorized output if color_option is enabled.  */
 static void
 pr_sgr_end_if (char const *s)
 {
@@ -443,6 +449,7 @@ static const struct color_cap color_dict[] =
    with EACCES.  */
 static int stdout_errno;
 
+/* Write character C to stdout and set stdout_errno if it fails.  */
 static void
 putchar_errno (int c)
 {
@@ -450,6 +457,7 @@ putchar_errno (int c)
     stdout_errno = errno;
 }
 
+/* Write string S to stdout and set stdout_errno if it fails.  */
 static void
 fputs_errno (char const *s)
 {
@@ -457,6 +465,7 @@ fputs_errno (char const *s)
     stdout_errno = errno;
 }
 
+/* Write formatted output to stdout and set stdout_errno if it fails.  */
 static void _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2)
 printf_errno (char const *format, ...)
 {
@@ -467,6 +476,7 @@ printf_errno (char const *format, ...)
   va_end (ap);
 }
 
+/* Write SIZE * NMEMB bytes from PTR to stdout and set stdout_errno if it fails.  */
 static void
 fwrite_errno (void const *ptr, idx_t size, idx_t nmemb)
 {
@@ -474,6 +484,7 @@ fwrite_errno (void const *ptr, idx_t size, idx_t nmemb)
     stdout_errno = errno;
 }
 
+/* Flush stdout and set stdout_errno if it fails.  */
 static void
 fflush_errno (void)
 {
@@ -1507,8 +1518,9 @@ grepbuf (char *beg, char const *lim)
   return outleft0 - outleft;
 }
 
-/* Search a given (non-directory) file.  Return a count of lines printed.
-   Set *INEOF to true if end-of-file reached.  */
+/* Search a given file descriptor FD with status ST.
+   Set *INEOF to true if end-of-file was reached.
+   Return the number of matching lines found.  */
 static intmax_t
 grep (int fd, struct stat const *st, bool *ineof)
 {
@@ -1967,6 +1979,7 @@ grep_command_line_arg (char const *arg)
     }
 }
 
+/* Print a usage message and exit with STATUS.  */
 _Noreturn void usage (int);
 void
 usage (int status)
-- 
2.53.0.windows.2

