Re: mg: fix tagfile parsing

2023-03-28 Thread Omar Polo
On 2023/03/28 22:25:42 +0200, Theo Buehler  wrote:
> Contrary to what I convinced op@ to be the case, duplicate tags may exist
> in legitimate tags files. So we should ignore duplicates rather than
> erroring on them. This fixes parsing the /var/db/libc.tags file.
> 
> $ grep -wc ^memcpy /var/db/libc.tags
> 2

oh... good to know that there may be duplicates.  it would be nice to
have mg record all of the tags (dups included) and allow the user to
choose where to jump when there are multiple location.  Overkill for
now however.

OK for me, thanks!

> Index: tags.c
> ===
> RCS file: /cvs/src/usr.bin/mg/tags.c,v
> retrieving revision 1.23
> diff -u -p -r1.23 tags.c
> --- tags.c22 Mar 2023 22:09:37 -  1.23
> +++ tags.c28 Mar 2023 19:55:17 -
> @@ -388,8 +388,10 @@ addctag(char *s)
>   if (*l == '\0')
>   goto cleanup;
>   t->pat = strip(l, strlen(l));
> - if (RB_INSERT(tagtree, , t) != NULL)
> - goto cleanup;
> + if (RB_INSERT(tagtree, , t) != NULL) {
> + free(t);
> + free(s);
> + }
>   return (TRUE);
>  cleanup:
>   free(t);



mg: fix tagfile parsing

2023-03-28 Thread Theo Buehler
Contrary to what I convinced op@ to be the case, duplicate tags may exist
in legitimate tags files. So we should ignore duplicates rather than
erroring on them. This fixes parsing the /var/db/libc.tags file.

$ grep -wc ^memcpy /var/db/libc.tags
2

Index: tags.c
===
RCS file: /cvs/src/usr.bin/mg/tags.c,v
retrieving revision 1.23
diff -u -p -r1.23 tags.c
--- tags.c  22 Mar 2023 22:09:37 -  1.23
+++ tags.c  28 Mar 2023 19:55:17 -
@@ -388,8 +388,10 @@ addctag(char *s)
if (*l == '\0')
goto cleanup;
t->pat = strip(l, strlen(l));
-   if (RB_INSERT(tagtree, , t) != NULL)
-   goto cleanup;
+   if (RB_INSERT(tagtree, , t) != NULL) {
+   free(t);
+   free(s);
+   }
return (TRUE);
 cleanup:
free(t);