From: Christopher Dykes Date: Sat, 2 Jul 2016 03:34:53 +0000 (-0700) Subject: Don't use a VLA for the dest buffer when testing wide FBString to multi-byte FBString X-Git-Tag: 2016.07.26~86 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=b292dfea24ac8d9b1a4c0bd2ab9bf1b751ec7cb3;p=folly.git Don't use a VLA for the dest buffer when testing wide FBString to multi-byte FBString Summary: Because MSVC doesn't support VLA's. Reviewed By: yfeldblum Differential Revision: D3507441 fbshipit-source-id: a50bdbad31674d236e4994903c75232d70f32bc0 --- diff --git a/folly/io/async/test/EventBaseTest.cpp b/folly/io/async/test/EventBaseTest.cpp index d5998bf1..cfea5991 100644 --- a/folly/io/async/test/EventBaseTest.cpp +++ b/folly/io/async/test/EventBaseTest.cpp @@ -53,9 +53,10 @@ enum { BUF_SIZE = 4096 }; ssize_t writeToFD(int fd, size_t length) { // write an arbitrary amount of data to the fd - char buf[length]; - memset(buf, 'a', sizeof(buf)); - ssize_t rc = write(fd, buf, sizeof(buf)); + auto bufv = vector(length); + auto buf = bufv.data(); + memset(buf, 'a', length); + ssize_t rc = write(fd, buf, length); CHECK_EQ(rc, length); return rc; } @@ -79,8 +80,8 @@ size_t writeUntilFull(int fd) { ssize_t readFromFD(int fd, size_t length) { // write an arbitrary amount of data to the fd - char buf[length]; - return read(fd, buf, sizeof(buf)); + auto buf = vector(length); + return read(fd, buf.data(), length); } size_t readUntilEmpty(int fd) { diff --git a/folly/test/FBStringTest.cpp b/folly/test/FBStringTest.cpp index 3d39b773..e8644482 100644 --- a/folly/test/FBStringTest.cpp +++ b/folly/test/FBStringTest.cpp @@ -1018,8 +1018,9 @@ TEST(FBString, testAllClauses) { rng = RandomT(localSeed); f_wfbstring(wc); int wret = wcslen(wc.c_str()); - char mb[wret+1]; - int ret = wcstombs(mb, wc.c_str(), sizeof(mb)); + auto mbv = std::vector(wret + 1); + auto mb = mbv.data(); + int ret = wcstombs(mb, wc.c_str(), wret + 1); if (ret == wret) mb[wret] = '\0'; const char *mc = c.c_str(); std::string one(mb);