Skip to content

Commit

Permalink
replace strcpy
Browse files Browse the repository at this point in the history
The behavior of `strcpy` is undefined when the `char *s` overlap. This
causes issues when compiling on macOS or with a different libc.

Instead of using `strcpy`, write and use `Xstrcpy`, which works on
overlapping and non-overlapping `char *`s.

`Xstrcpy` does have an additional difference, which is that it returns
the `int` `1` instead of a `char *`. The codebase never uses the result
of `strcpy`, though, so this shouldn't be a problem.
  • Loading branch information
zfletch committed Jul 3, 2018
1 parent f0b825a commit f9d1ae5
Show file tree
Hide file tree
Showing 105 changed files with 531 additions and 525 deletions.
2 changes: 1 addition & 1 deletion src/anal/GetSel.c
Expand Up @@ -21,4 +21,4 @@ char *s2;
}
}

}
}
2 changes: 1 addition & 1 deletion src/anal/MorphWind.c
Expand Up @@ -1100,4 +1100,4 @@ SKErrMess(void)
SelectWindow(ErrWindow);

DisplayText(ErrMess,(long)strlen(ErrMess));
}
}
2 changes: 1 addition & 1 deletion src/anal/betamorph.c
Expand Up @@ -23,4 +23,4 @@ _main(void)
if( ++nverbs > 10 ) break;

}
}
}
4 changes: 2 additions & 2 deletions src/anal/chckcmpstem.c
Expand Up @@ -11,13 +11,13 @@ FILE * f;
char stemkeys[LONGSTRING];
int rval = 0;

strcpy(tmp,s);
Xstrcpy(tmp,s);
p = tmp;
while(*p) p++;
p--;

if( isdigit(*s) ) return;
strcpy(endkeys,"os_ou os_h_on os_on h_hs a_hs");
Xstrcpy(endkeys,"os_ou os_h_on os_on h_hs a_hs");
while(p>tmp) {
if( *p == 'o' || *p == 'h' ) {
*p = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/anal/checkdict.c
Expand Up @@ -46,7 +46,7 @@ checkdict(gk_word *Gkword, gk_string *stem, char *stemkeys)
} else
zap_morphflag(morphflags_of(Gkword),SYLL_AUGMENT);

strcpy(keyp , GetLemmStem(curkeys,lemma_of(Gkword),stem_of(Gkword)));
Xstrcpy(keyp , GetLemmStem(curkeys,lemma_of(Gkword),stem_of(Gkword)));
pbptr = is_substring("pb:",keyp);
/*
*
Expand Down Expand Up @@ -85,7 +85,7 @@ fprintf(stderr,"checkdict: stem [%s] endstring [%s] keyp [%s]\n", stem_of(Gkword
else {
char tmppb[LONGSTRING];

strcpy(tmppb,pbptr+3);
Xstrcpy(tmppb,pbptr+3);
if( *(lastn(tmppb,1)) == ':' ) *(lastn(tmppb,1)) = 0;
/*
* grc 6/29/89
Expand Down
6 changes: 3 additions & 3 deletions src/anal/checkgenwds.c
Expand Up @@ -86,7 +86,7 @@ printf("\nin checkgenword accword [%s]\n", accword );
if( (prntflags_of(Gkword) & IGNORE_ACCENTS) ) {
char wordnoacc[MAXWORDSIZE];

strcpy(wordnoacc,wordnoacute);
Xstrcpy(wordnoacc,wordnoacute);
stripacc(wordnoacc);
checks = wordnoacc;

Expand Down Expand Up @@ -246,7 +246,7 @@ printf("tmphalf1 [%s] s [%s]\n", tmphalf1, s );
if( tmphalf1[0] ) {
strcat(tmphalf1,"-");
strcat(tmphalf1,cmplem);
strcpy(cmplem,tmphalf1);
Xstrcpy(cmplem,tmphalf1);
}
break;
}
Expand All @@ -259,7 +259,7 @@ printf("s [%s] tmplem [%s] tmphalf1 [%s] t [%s] cmplem[%s]\n", s , tmplem , tmph
if(!s ) {
if( tmphalf1[0] ) strcat(tmphalf1,",");
strcat(tmphalf1,t);
strcpy(tmplem,tmphalf1);
Xstrcpy(tmplem,tmphalf1);
break;
}
*s++ = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/anal/checkhalf1.c
Expand Up @@ -21,7 +21,7 @@ checkhalf1(gk_word *Gkword, char *endkeys)
/*
printf("half1 stem preverb [%s] stem [%s] end [%s]\n", preverb_of(Gkword) , stem_of(Gkword), endstring_of(Gkword));
*/
strcpy(savestem,stem);
Xstrcpy(savestem,stem);
if( *stem == 'r' && getbreath(stem) == NOBREATH && cur_lang() == GREEK) {
char tmp[MAXWORDSIZE];

Expand Down Expand Up @@ -123,7 +123,7 @@ printf("half1 stem preverb [%s] stem [%s] end [%s]\n", preverb_of(Gkword) , stem
stripbreath(stem);
diaerstem[0] = *stem;
diaerstem[1] = DIAERESIS;
strcpy(diaerstem+2,stem+1);
Xstrcpy(diaerstem+2,stem+1);
addbreath(diaerstem,cbreath);
set_stem(Gkword,diaerstem);
rval+=checkhalf2(Gkword,endkeys);
Expand All @@ -134,7 +134,7 @@ printf("half1 stem preverb [%s] stem [%s] end [%s]\n", preverb_of(Gkword) , stem
(AndDialect(dialect_of(Gkword),(Dialect)IONIC)>=0) &&
cur_lang() != LATIN ) {
add_morphflag(morphflags_of(Gkword),UNASP_PREVERB);
strcpy(stem,savestem);
Xstrcpy(stem,savestem);
stripbreath(stem);
addbreath(stem,ROUGHBR);
rval+=checkhalf2(Gkword,endkeys);
Expand Down
4 changes: 2 additions & 2 deletions src/anal/checkstem.c
Expand Up @@ -250,13 +250,13 @@ char * s;
char stemkeys[1024];
int rval = 0;

strcpy(tmp,s);
Xstrcpy(tmp,s);
stemkeys[0] = 0;
p = tmp;

while(*p) p++; p--;
while(p>=tmp) {
strcpy(tmp2,p);
Xstrcpy(tmp2,p);
*p = 0;
if( (rval += chckstem(tmp,stemkeys,1)) ) {
printf("%s-%s\tn\t%s\n", tmp, tmp2, stemkeys );
Expand Down
24 changes: 12 additions & 12 deletions src/anal/checkstring.c
Expand Up @@ -71,7 +71,7 @@ cntlems(gk_word *Gkword )
if( strcmp(prevlem,lemma_of(Anal))) {
cnt++;
}
strcpy(prevlem,lemma_of(Anal));
Xstrcpy(prevlem,lemma_of(Anal));
}
return(cnt);
}
Expand Down Expand Up @@ -110,7 +110,7 @@ checkstring1(gk_word *Gkword)
if( ! n /* && ! hasaccent(savework) */) {
char tmp[MAXWORDSIZE];

strcpy(tmp,savework);
Xstrcpy(tmp,savework);
if( hasaccent(tmp) ) stripacc(tmp);
set_workword(Gkword,"e)/");
Xstrncat(workword_of(Gkword),tmp+1,MAXWORDSIZE);
Expand Down Expand Up @@ -437,7 +437,7 @@ checkstring3(gk_word *Gkword)
cmpend(workword_of(Gkword),"emst",workword) ||
cmpend(workword_of(Gkword),"omst",workword))
{
strcpy(workword,workword_of(Gkword));
Xstrcpy(workword,workword_of(Gkword));
workword[strlen(workword)-2] = 0;
set_workword(Gkword,workword);
rval = checkstring3(Gkword);
Expand All @@ -451,7 +451,7 @@ checkstring3(gk_word *Gkword)
/* ...us + est written as ...ust */
if (cmpend(workword_of(Gkword), "ust", workword))
{
strcpy(workword, workword_of(Gkword));
Xstrcpy(workword, workword_of(Gkword));
workword[strlen(workword) - 1] = 0;
set_workword(Gkword,workword);
rval = checkstring3(Gkword);
Expand All @@ -467,7 +467,7 @@ checkstring3(gk_word *Gkword)
if (cmpend(workword_of(Gkword), "ist", workword) ||
cmpend(workword_of(Gkword), "ost", workword))
{
strcpy(workword, workword_of(Gkword));
Xstrcpy(workword, workword_of(Gkword));
workword[strlen(workword) - 1] = 0; /* try -is first */
set_workword(Gkword,workword);
workval = checkstring3(Gkword);
Expand Down Expand Up @@ -495,7 +495,7 @@ checkstring3(gk_word *Gkword)
{
if (cmpend(workword_of(Gkword), "n", workword))
{
strcpy(workword, workword_of(Gkword));
Xstrcpy(workword, workword_of(Gkword));
workword[strlen(workword) - 1] = 's'; /* ...s-ne -> ...n */
set_workword(Gkword, workword);
workval = checkstring3(Gkword);
Expand Down Expand Up @@ -575,7 +575,7 @@ checkstring3(gk_word *Gkword)
*/
if( cur_lang() == LATIN ) {
char * a = workword;
strcpy(workword,saveword);
Xstrcpy(workword,saveword);
if( u2v(workword) ) {
set_workword(Gkword,workword);
rval = checkstring3(Gkword);
Expand All @@ -584,13 +584,13 @@ checkstring3(gk_word *Gkword)
return(rval);
}
}
strcpy(workword,saveword);
Xstrcpy(workword,saveword);
}
/* If we're out of ideas in Italian, turn all u's to v's. */
else if ( (cur_lang() == ITALIAN) && !totanal_of(Gkword)) {
char *a;

strcpy(workword,saveword);
Xstrcpy(workword,saveword);

for (a = workword, acount = 0; *a != '\0'; a++) {
if (*a == 'U') {
Expand All @@ -612,7 +612,7 @@ checkstring3(gk_word *Gkword)
}
}

strcpy(workword,saveword);
Xstrcpy(workword,saveword);
}

/*
Expand All @@ -627,7 +627,7 @@ checkstring3(gk_word *Gkword)
*/
if( cur_lang() == LATIN ) {
char * a = workword;
strcpy(workword,saveword);
Xstrcpy(workword,saveword);

if( *a == 'I' ) {
*a = 'J';
Expand Down Expand Up @@ -671,7 +671,7 @@ checkstring3(gk_word *Gkword)
char* p_word = NULL;
char* p_tail = NULL;
char* p_start = NULL;
strcpy(workword, workword_of(Gkword));
Xstrcpy(workword, workword_of(Gkword));
p_word = workword;
p_word += 2;
switch (*p_word)
Expand Down

0 comments on commit f9d1ae5

Please sign in to comment.