From b9fe7472186b8d37f16aa6b7c6039e26b49cf6e4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 14 Oct 2015 17:28:36 -0400 Subject: [PATCH] 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. --- src/rtodms.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rtodms.c b/src/rtodms.c index abf6bc1c65..0f64b3d6c5 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