🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.4bsd
Article #328

I think i'm having a problem with re_cmp and re_exec

#328
From: Charles Shub
Date: Wed, 20 Feb 1991 05:13
83 lines
2867 bytes
Have I found a bug in re_cmp and re_exec?  If so, is there a fix??
if not, what am I doing wrong
please respond by mail as I do not subscribe to this group.
The problem seems to be in matching files with an input of <letter>*
I get a random match in this case.

charlie shub  cdash@boulder.Colorado.EDU  -or-  ..!{ucar|nbires}!boulder!cdash
  or even     cdash@colospgs (BITNET)     -or-  (719) 593-3492

Execution output
------------------------------
bug m*
enter a string >u*
'u*' 'u.*'  'moutgoing'  found 1
------------------------------
 ^    ^      ^
 |    |      -------  file matched by re_exec
 |    --------------  string fed to re_comp
 -------------------  input string

The directory has  42 entries including the following:

bulgren   
csu 
moutgoing
upe

Source code below (culled from huge program, recompiled, and run)

it is running on a microvax with 4.3 + nfs
------------------------------
#include <pwd.h>
#include <sys/types.h>
#include <strings.h>
#include <sys/dir.h>
main()
{
        DIR *dirp;
        struct direct *dp;
        char com[256], lstr[256];
        char *re_comp(), *ap, *lp;
        int found = 0;

        printf("enter a string >");
        gets(com);
        ap = com;
        lp = lstr;
        while (*ap) {
                if(*ap == '*') {
                        *lp++ = '.';
                        *lp++ = *ap++;
                }
                else {
                        *lp++ = *ap++;
                }
        }
        *lp = '\0';
        printf("'%s' '%s' ",com, lstr);
        if(ap = re_comp(lstr)) {
            printf("'%s' error %s",lp,ap);
        }
        else {
            int zz;
            dirp = opendir(".");
            while ((dp = readdir(dirp)) != NULL && !found) {
                if((zz = re_exec(dp->d_name)) < 0) {
                    printf("re_exec error");
                    break;
                }
                else if (zz) {
                    found = 1;
                    printf(" '%s' ",dp->d_name);
                }
            }
            closedir(dirp);
        }
        printf(" found %d\n",found);
}
------------------------------
-- 

charlie shub  cdash@boulder.Colorado.EDU  -or-  ..!{ucar|nbires}!boulder!cdash
  or even     cdash@colospgs (BITNET)     -or-  (719) 593-3492
Technical Details
Message-ID: <1991Feb20.051351.970@csn.org>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!csn!news

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!csn!news
From: cdash@mumm.colorado.edu (Charles Shub)
Newsgroups: comp.bugs.4bsd,comp.unix.wizards
Subject: I think i'm having a problem with re_cmp and re_exec
Message-ID: <1991Feb20.051351.970@csn.org>
Date: 20 Feb 91 05:13:51 GMT
Sender: news@csn.org (news)
Organization: University of Colorado at Colorado Springs
Lines: 83
Nntp-Posting-Host: mumm.colorado.edu