diff options
| author | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2015-10-14 17:28:36 -0400 |
|---|---|---|
| committer | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2015-10-14 18:58:24 -0400 |
| commit | 90e393396d0aad7f504b21bc25f87326d044da63 (patch) | |
| tree | e1e53f18396851d01afab82659233dfbdc32e642 /src | |
| parent | 6eabf3c854f3786fbaa1b645ea9e9aae6e4522e4 (diff) | |
| download | PROJ-90e393396d0aad7f504b21bc25f87326d044da63.tar.gz PROJ-90e393396d0aad7f504b21bc25f87326d044da63.zip | |
Avoid strcpy of overlapping strings.
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/rtodms.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/rtodms.c b/src/rtodms.c index 591874a6..fa7801c5 100644 --- a/src/rtodms.c +++ b/src/rtodms.c @@ -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 |
