[Rd] Bug in so_strsplit (PR#13742)

From: <waku_at_idi.ntnu.no>
Date: Tue, 02 Jun 2009 11:30:14 +0200 (CEST)


Full_Name: Wacek Kusnierczyk
Version: 2.10.0 r48689
OS: Ubuntu 8.04 Linux 32b
Submission from: (NULL) (129.241.199.78)

src/main/character.c:435-438 (do_strsplit) contains the following code:

    for (i = 0; i < tlen; i++)

        if (getCharCE(STRING_ELT(tok, 0)) == CE_UTF8) use_UTF8 = TRUE;     for (i = 0; i < len; i++)

        if (getCharCE(STRING_ELT(x, 0)) == CE_UTF8) use_UTF8 = TRUE;

both loops iterate over loop-invariant expressions and statements. either the loops are redundant, or the fixed index '0' is copied over from some other place and should be replaced with 'i'.

the bug can be fixed with

    for (i = 0; i < tlen; i++)

        if (getCharCE(STRING_ELT(tok, i)) == CE_UTF8) {
            use_UTF8 = TRUE;
            break; }
    for (i = 0; i < len; i++)
        if (getCharCE(STRING_ELT(x, i)) == CE_UTF8) {
            use_UTF8 = TRUE;
            break; }
            

or with

   #define CHECK_CE(CHARACTER, LENGTH, USEUTF8) \

      for (i = 0; i < (LENGTH); i++) \
         if (getCharCE(STRING_ELT((CHARACTER), i)) == CE_UTF8) { \
            (USEUTF8) = TRUE; \
            break; }

   CHECK_CE(tok, tlen, use_UTF8)
   CHECK_CE(x, len, use_UTF8)

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 02 Jun 2009 - 09:44:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 02 Jun 2009 - 12:34:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive