bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gawk substr() problem


From: Aharon Robbins
Subject: Re: gawk substr() problem
Date: Thu, 21 Nov 2002 16:13:22 +0200

Paul,

Re your patch,  I like the idea of printing the length and index values
using %g and will do that.  But I have a question about some of the
other bits.

How does casting -1 to a size_t improve anything?  size_t is unsigned
long (or long long), so you just end up with MAX_ULONG or some such.
Wouldn't just (size_t) ~0  be a better value?  In other words, what
are you trying to accomplish, and how does casting -1 to size_t
accomplish it?

Also:

        if (t1->stlen == 0) {
-               if (do_lint)
+               if (do_lint && (indx | length) != 0)
                        lintwarn(_("substr: source string is zero length"));

That's not right: If the source string length is zero, there's
no reason to check the index and length.  Or are you trying to
avoid a warning on

        substr("", 1, 0)

?

As to whether a 0 length should be a warning or not,

> But the string _does_ match this pattern.  The pattern is supposed to
> grab the leading digits, if any.  If there are no leading digits, then
> the pattern matches the empty string.

In your example, yes.

> > My take is that asking for a zero-length substring is "most likely"
> > to be unintentional,

I was talking about the general case, but I didn't make that clear.

Neither of us has done a scientific survey.  I did the warning based on
what I'd like to see gawk warn about for my own awk programs.  I rarely
want zero length strings from substr(), so if I'm getting one, I'd like
to know about it.

Anyone who's REALLY bothered by the warning can develop their own private
patch that removes the warning, and apply it to the gawk release before
building and installing it.

> > It's only a lint warning, and I am fairly well convinced that nobody
> > uses --lint anyway.
>
> I didn't know about --lint until recently, but if --lint generates
> warnings for perfectly-reasonable

Valid and reasonable are two different things, and in my judgement and
experience, MOST OF THE TIME, a zero-length string is worth a warning.

> things like zero-length substrings,
> I don't wonder that nobody uses it.

I find this remark rude and uncalled-for, especially on a public
mailing list.  I think you owe me an apology.

Arnold





reply via email to

[Prev in Thread] Current Thread [Next in Thread]