Bug 1333 - awk error in gsub function
Summary: awk error in gsub function
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.12.x
Hardware: Other Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-17 00:15 UTC by Andy Lord
Modified: 2023-06-08 08:52 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Lord 2010-03-17 00:15:32 UTC
gsub() ignoring word boundary

# echo 'abc' | awk '{ gsub(/\<b*/,""); print; }'
ac
# echo 'abc' | awk '{ sub(/\<b*/,""); print; }'
abc

Probably something to do with backtracking....

Compare gawk:

$ echo 'abc' | awk '{ gsub(/\<b*/,""); print; }'
abc

$ echo 'abc' | awk '{ sub(/\<b*/,""); print; }'
abc

Seen on media player

BusyBox v1.12.4 (2008-12-31 22:38:12 CET) multi-call binary
Linux hdx 2.6.15-sigma #953 PREEMPT Wed Jun 3 21:49:15 CST 2009 mips unknown

and router

BusyBox v1.12.3 (2008-12-14 02:54:58 PST) built-in shell (ash)
Linux unknown 2.4.20 #1 Sun Dec 14 03:03:26 PST 2008 mips unknown
Comment 1 Denys Vlasenko 2010-04-03 23:49:53 UTC
I see where it happens. Added comments in awk_sub() about it.
Unfortunately, no easy fix. Need to use GNU regex matching, not POSIX one, to do it right.
Comment 2 Denys Vlasenko 2023-06-08 08:52:00 UTC
commit 2ca39ffd447ca874fcea933194829717d5573247
Date:   Thu Jun 8 10:42:39 2023 +0200

    awk: fix subst code to handle "start of word" pattern correctly (needs REG_STARTEND)