From A.R.Runnalls at kent.ac.uk  Wed Jan  2 18:45:38 2008
From: A.R.Runnalls at kent.ac.uk (A.R.Runnalls at kent.ac.uk)
Date: Wed,  2 Jan 2008 18:45:38 +0100 (CET)
Subject: [Rd] do_gsub (PR#10540)
Message-ID: <20080102174538.4B6D7283416A@mail.pubhealth.ku.dk>

In character.c within R 2.6.1, the function do_gsub contains the following 
code:

1199        if (STRING_ELT(pat, 0) == NA_STRING) {
1200            PROTECT(ans = allocVector(STRSXP, n));
1201            for(i = 0; i < n; i++)  SET_STRING_ELT(ans, i, NA_STRING);
1202            UNPROTECT(1);
1203            return ans;
1204        }
1205
1206        if (length(pat) < 1 || length(rep) < 1) error(R_MSG_IA);

Line 1206 checks that pat contains at least one element.  However, line 1199 
has already attempted to access the first element.  The check should surely 
come first.

Andrew Runnalls



[Rd] do_gsub (PR#10540)
A.R.Runnalls at kent.ac.uk