Dominique Pellé wrote: > The proposed patch fixes that issue in `find.c` by making sure > the returned `char*` is '\0' terminated. ...snip... > The proposed patch also fixes unrelated typos in > comments and in the cscope man pages. ...snip...
I do not see that patch that I attached in my previous message in the mailing list archive. I suppose that attachments are not permitted. I therefore put the patch inline below (the important part for the bug fix is in find.c): diff -c -r cscope-15.9/doc/xcscope.1 cscope-15.9-fixed/doc/xcscope.1 *** cscope-15.9/doc/xcscope.1 2017-11-07 01:14:58.000000000 +0100 --- cscope-15.9-fixed/doc/xcscope.1 2022-05-01 08:11:24.000000000 +0200 *************** *** 1,6 **** '\" t .\" The xcscope.el man page ! .\" Origionally written by Darryl Okahata, Apr 2000 .\" .\" Converted to a man page July 20, 2004 by Neil Horman <nhor...@redhat.com> .\" --- 1,6 ---- '\" t .\" The xcscope.el man page ! .\" Originally written by Darryl Okahata, Apr 2000 .\" .\" Converted to a man page July 20, 2004 by Neil Horman <nhor...@redhat.com> .\" *************** *** 152,158 **** .P If a search is initiated from a .c file in /users/jdoe/sources/proj1 then (assuming the variable, `cscope-database-regexps', is not set) ! /users/jdoe/sources/proj1 will be used as the cscope data base directory. Only matches in files in /users/jdoe/sources/proj1 will be found. This can be remedied by typing "C-c s a" and then "M-del" to remove single path element in order to use a cscope database directory of --- 152,158 ---- .P If a search is initiated from a .c file in /users/jdoe/sources/proj1 then (assuming the variable, `cscope-database-regexps', is not set) ! /users/jdoe/sources/proj1 will be used as the cscope database directory. Only matches in files in /users/jdoe/sources/proj1 will be found. This can be remedied by typing "C-c s a" and then "M-del" to remove single path element in order to use a cscope database directory of *************** *** 173,179 **** C-c s g Find global definition (alternate binding). C-c s G Find global definition without prompting. C-c s c Find functions calling a function. ! C-c s C Find called functions (list functions called C-c s t Find text string. C-c s e Find egrep pattern. C-c s f Find a file. --- 173,179 ---- C-c s g Find global definition (alternate binding). C-c s G Find global definition without prompting. C-c s c Find functions calling a function. ! C-c s C Find called functions (list functions called) C-c s t Find text string. C-c s e Find egrep pattern. C-c s f Find a file. *************** *** 527,533 **** .P 1. The script, "cscope-indexer", uses a sed command to determine ! what is and is not a C/C++/lex/yacc source file. It's idea of a source file may not correspond to yours. .P --- 527,533 ---- .P 1. The script, "cscope-indexer", uses a sed command to determine ! what is and is not a C/C++/lex/yacc source file. Its idea of a source file may not correspond to yours. .P diff -c -r cscope-15.9/src/build.c cscope-15.9-fixed/src/build.c *** cscope-15.9/src/build.c 2017-11-07 01:14:58.000000000 +0100 --- cscope-15.9-fixed/src/build.c 2022-05-01 12:57:15.000000000 +0200 *************** *** 133,139 **** } ! /* create the file name(s) used for a new cross-referene */ void setup_build_filenames(char *reffile) { --- 133,139 ---- } ! /* create the file name(s) used for a new cross-reference */ void setup_build_filenames(char *reffile) { diff -c -r cscope-15.9/src/command.c cscope-15.9-fixed/src/command.c *** cscope-15.9/src/command.c 2018-07-19 21:45:17.000000000 +0200 --- cscope-15.9-fixed/src/command.c 2022-05-01 08:05:54.000000000 +0200 *************** *** 887,893 **** filelen = 4; /* strlen("File") */ fcnlen = 8; /* strlen("Function") */ numlen = 0; ! /* HBB NOTE 2012-04-07: it may look like we shouldn't assing tempstring here, * since it's not used. But it has to be assigned just so the return value * of fscanf will actually reach 4. */ while (EOF != (i = fscanf(refsfound, --- 887,893 ---- filelen = 4; /* strlen("File") */ fcnlen = 8; /* strlen("Function") */ numlen = 0; ! /* HBB NOTE 2012-04-07: it may look like we shouldn't assigning tempstring here, * since it's not used. But it has to be assigned just so the return value * of fscanf will actually reach 4. */ while (EOF != (i = fscanf(refsfound, diff -c -r cscope-15.9/src/compath.c cscope-15.9-fixed/src/compath.c *** cscope-15.9/src/compath.c 2017-11-07 01:14:58.000000000 +0100 --- cscope-15.9-fixed/src/compath.c 2022-05-01 08:04:51.000000000 +0200 *************** *** 40,46 **** * * WARNING: since pathname is altered by this function, it should * be located in a temporary buffer. This avoids the problem ! * of accidently changing strings obtained from makefiles * and stored in global structures. */ --- 40,46 ---- * * WARNING: since pathname is altered by this function, it should * be located in a temporary buffer. This avoids the problem ! * of accidentally changing strings obtained from makefiles * and stored in global structures. */ diff -c -r cscope-15.9/src/find.c cscope-15.9-fixed/src/find.c *** cscope-15.9/src/find.c 2018-03-19 22:37:27.000000000 +0100 --- cscope-15.9-fixed/src/find.c 2022-05-01 12:57:59.000000000 +0200 *************** *** 48,53 **** --- 48,55 ---- #endif #include <regex.h> + #define BUFFER_SIZE 8192 + /* most of these functions have been optimized so their innermost loops have * only one test for the desired character by putting the char and * an end-of-block marker (\0) at the end of the disk block buffer. *************** *** 57,63 **** */ char *blockp; /* pointer to current char in block */ ! char block[BUFSIZ + 2]; /* leave room for end-of-block mark */ int blocklen; /* length of disk block read */ char blockmark; /* mark character to be searched for */ long blocknumber; /* block number */ --- 59,65 ---- */ char *blockp; /* pointer to current char in block */ ! char block[BUFFER_SIZE + 2]; /* leave room for end-of-block mark */ int blocklen; /* length of disk block read */ char blockmark; /* mark character to be searched for */ long blocknumber; /* block number */ *************** *** 872,879 **** if (--cp < block) { retreat = YES; /* read the previous block */ ! (void) dbseek((blocknumber - 1) * BUFSIZ); ! cp = block + (BUFSIZ - 1); } } blockp = cp; --- 874,881 ---- if (--cp < block) { retreat = YES; /* read the previous block */ ! (void) dbseek((blocknumber - 1) * BUFFER_SIZE); ! cp = block + (BUFFER_SIZE - 1); } } blockp = cp; *************** *** 975,981 **** } ! /* scan past the next occurence of this character in the cross-reference */ char * scanpast(char c) { --- 977,983 ---- } ! /* scan past the next occurrence of this character in the cross-reference */ char * scanpast(char c) { *************** *** 1001,1007 **** read_block(void) { /* read the next block */ ! blocklen = read(symrefs, block, BUFSIZ); blockp = block; /* add the search character and end-of-block mark */ --- 1003,1009 ---- read_block(void) { /* read the next block */ ! blocklen = read(symrefs, block, BUFFER_SIZE); blockp = block; /* add the search character and end-of-block mark */ *************** *** 1035,1041 **** /* find the functions called by this function */ ! /* HBB 2000/05/05: for consitency of calling interface between the * different 'find...()' functions, this now returns a char pointer, * too. Implemented as a pointer to static storage containing 'y' or * 'n', for the boolean result values YES and NO */ --- 1037,1043 ---- /* find the functions called by this function */ ! /* HBB 2000/05/05: for consistency of calling interface between the * different 'find...()' functions, this now returns a char pointer, * too. Implemented as a pointer to static storage containing 'y' or * 'n', for the boolean result values YES and NO */ *************** *** 1044,1050 **** findcalledby(char *pattern) { char file[PATHLEN + 1]; /* source file name */ ! static char found_caller = 'n'; /* seen calling function? */ BOOL macro = NO; if (invertedindex == YES) { --- 1046,1052 ---- findcalledby(char *pattern) { char file[PATHLEN + 1]; /* source file name */ ! static char found_caller[2] = "n"; /* seen calling function? */ BOOL macro = NO; if (invertedindex == YES) { *************** *** 1057,1068 **** case FCNDEF: if (dbseek(p->lineoffset) != -1 && scanpast('\t') != NULL) { /* skip def */ ! found_caller = 'y'; findcalledbysub(srcfiles[p->fileindex], macro); } } } ! return(&found_caller); } /* find the function definition(s) */ while (scanpast('\t') != NULL) { --- 1059,1070 ---- case FCNDEF: if (dbseek(p->lineoffset) != -1 && scanpast('\t') != NULL) { /* skip def */ ! found_caller[0] = 'y'; findcalledbysub(srcfiles[p->fileindex], macro); } } } ! return(&found_caller[0]); } /* find the function definition(s) */ while (scanpast('\t') != NULL) { *************** *** 1072,1078 **** skiprefchar(); /* save file name */ fetch_string_from_dbase(file, sizeof(file)); if (*file == '\0') { /* if end of symbols */ ! return(&found_caller); } progress("Search", searchcount, nsrcfiles); break; --- 1074,1080 ---- skiprefchar(); /* save file name */ fetch_string_from_dbase(file, sizeof(file)); if (*file == '\0') { /* if end of symbols */ ! return(&found_caller[0]); } progress("Search", searchcount, nsrcfiles); break; *************** *** 1087,1100 **** case FCNDEF: skiprefchar(); /* match name to pattern */ if (match()) { ! found_caller = 'y'; findcalledbysub(file, macro); } break; } } ! return (&found_caller); } /* find this term, which can be a regular expression */ --- 1089,1102 ---- case FCNDEF: skiprefchar(); /* match name to pattern */ if (match()) { ! found_caller[0] = 'y'; findcalledbysub(file, macro); } break; } } ! return (&found_caller[0]); } /* find this term, which can be a regular expression */ *************** *** 1236,1243 **** long n; int rc = 0; ! if ((n = offset / BUFSIZ) != blocknumber) { ! if ((rc = lseek(symrefs, n * BUFSIZ, 0)) == -1) { myperror("Lseek failed"); (void) sleep(3); return(rc); --- 1238,1245 ---- long n; int rc = 0; ! if ((n = offset / BUFFER_SIZE) != blocknumber) { ! if ((rc = lseek(symrefs, n * BUFFER_SIZE, 0)) == -1) { myperror("Lseek failed"); (void) sleep(3); return(rc); *************** *** 1245,1251 **** (void) read_block(); blocknumber = n; } ! blockp = block + offset % BUFSIZ; return(rc); } --- 1247,1253 ---- (void) read_block(); blocknumber = n; } ! blockp = block + offset % BUFFER_SIZE; return(rc); } diff -c -r cscope-15.9/src/main.c cscope-15.9-fixed/src/main.c *** cscope-15.9/src/main.c 2018-07-19 21:45:17.000000000 +0200 --- cscope-15.9-fixed/src/main.c 2022-05-01 08:03:54.000000000 +0200 *************** *** 884,890 **** break; #endif } ! /* execute the commmand, updating the display if necessary */ if (command(c) == YES) { display(); } --- 884,890 ---- break; #endif } ! /* execute the command, updating the display if necessary */ if (command(c) == YES) { display(); } _______________________________________________ Cscope-devel mailing list Cscope-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cscope-devel