Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mac build broken by #define of strcpy (conflicts with Apple's fortify implementation) #35

Closed
enh-google opened this issue Aug 13, 2021 · 2 comments

Comments

@enh-google
Copy link

seems like the attempt to use strcpy_s() on Windows broke the macOS build. it conflicts with the mac's _FORTIFY_SOURCE implementation (which [TIL] appears to be on by default), which has a #define of strcpy to __builtin_strcpy_chk.

here's the easiest option... i went with a new name because i assume you do want fortify where available rather than, say, strncpy() or strlcpy() --- certainly fortify seems closest to strcpy_s():

diff --git a/include/vector.h b/include/vector.h
index 8f7cbbcc..948e4751 100644
--- a/include/vector.h
+++ b/include/vector.h
@@ -441,7 +441,7 @@ void bc_slabvec_print(BcVec *v, const char *func);
  *           contain @a s.
  * @param s  The source string.
  */
-#define strcpy(d, l, s) strcpy(d, s)
+#define lstrcpy(d, l, s) strcpy(d, s)
 
 #else // _WIN32
 
@@ -452,7 +452,7 @@ void bc_slabvec_print(BcVec *v, const char *func);
  *           contain @a s.
  * @param s  The source string.
  */
-#define strcpy(d, l, s) strcpy_s(d, l, s)
+#define lstrcpy(d, l, s) strcpy_s(d, l, s)
 
 #endif // _WIN32
 
diff --git a/src/vector.c b/src/vector.c
index 1cd90f72..022a8548 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -461,7 +461,7 @@ static char* bc_slab_add(BcSlab *s, const char *str, size_t len) {
 
        ptr = (char*) (s->s + s->len);
 
-       strcpy(ptr, len, str);
+       lstrcpy(ptr, len, str);
 
        s->len += len;
 

(we don't have mac presubmit, so i didn't notice this until i submitted the upgrade this morning.)

@gavinhoward
Copy link
Owner

I have tweaked your fix, tested it, and it works. So I've released 5.0.1, and you should be good to go.

Please reopen if something go wrong.

@gavinhoward
Copy link
Owner

Oh, yeah, forgot to say: FreeBSD didn't tell me about any more problems and seem to have solved it on their end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants