Skip to content

Commit

Permalink
Avoid strcpy of overlapping strings.
Browse files Browse the repository at this point in the history
The source and destination for strcpy must not overlap, and failure to
ensure that's true causes a crash on OS X. memmove does not have such a
restriction.
  • Loading branch information
QuLogic authored and rouault committed Oct 17, 2015
1 parent 0742275 commit b9fe747
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/rtodms.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ rtodms(char *s, double r, int pos, int neg) {
(void)sprintf(ss,format,deg,min,sec,sign);
else if (sec) {
char *p, *q;
/* double prime + pos/neg suffix (if included) + NUL */
size_t suffix_len = sign ? 3 : 2;

(void)sprintf(ss,format,deg,min,sec,sign);
for (q = p = ss + strlen(ss) - (sign ? 3 : 2); *p == '0'; --p) ;
for (q = p = ss + strlen(ss) - suffix_len; *p == '0'; --p) ;
if (*p != '.')
++p;
if (++q != p)
(void)strcpy(p, q);
(void)memmove(p, q, suffix_len);
} else if (min)
(void)sprintf(ss,"%dd%d'%c",deg,min,sign);
else
Expand Down

0 comments on commit b9fe747

Please sign in to comment.