summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2015-07-28 11:11:06 -0400
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2015-07-28 11:11:06 -0400
commita5ff92b9ff97713deab61c69407d293b8ef064a8 (patch)
tree8a6c0f189fd2b0da44ed5e204ea917cf5c774e9d
parent2f6799a42360a995b665244b922ebd3b2275c839 (diff)
Run cpplint
Also fix a fencepost error in uw_Regex__FFI_do_match.
-rw-r--r--src/regex__FFI.cc30
-rw-r--r--src/regex__FFI.h6
2 files changed, 22 insertions, 14 deletions
diff --git a/src/regex__FFI.cc b/src/regex__FFI.cc
index c2f8a4b..c89aa4c 100644
--- a/src/regex__FFI.cc
+++ b/src/regex__FFI.cc
@@ -12,17 +12,18 @@
// License for the specific language governing permissions and limitations under
// the License.
-#include "regex__FFI.h"
+#include "src/regex__FFI.h"
+#include <cstdio>
#include <cstring>
-#include <regex>
+#include <regex> // NOLINT(build/c++11)
-#include <boost/numeric/conversion/cast.hpp>
+#include <boost/numeric/conversion/cast.hpp> // NOLINT(build/include_order)
extern "C" {
-#include <urweb/urweb_cpp.h>
+#include <urweb/urweb_cpp.h> // NOLINT(build/include_order)
}
-#include "config.h"
+#include "./config.h"
namespace {
@@ -89,7 +90,7 @@ uw_Basis_int uw_Regex__FFI_n_subexpression_matches(
uw_Basis_string uw_Regex__FFI_subexpression_match(
uw_context* const context,
- const uw_Regex__FFI_match match,
+ const uw_Regex__FFI_match match,
const uw_Basis_int match_index_signed) {
const std::cmatch* const match_result =
reinterpret_cast<std::cmatch*>(match.result);
@@ -100,10 +101,13 @@ uw_Basis_string uw_Regex__FFI_subexpression_match(
const auto matched_substring = (*match_result)[match_index + 1];
// Save the matched substring.
const std::size_t result_length =
- Number<std::size_t>(context,matched_substring.length());
+ Number<std::size_t>(context, matched_substring.length());
uw_Basis_string result =
reinterpret_cast<uw_Basis_string>(uw_malloc(context, result_length + 1));
- std::strcpy(result, matched_substring.str().c_str());
+ Assert(context,
+ std::snprintf(result, result_length + 1, "%s",
+ matched_substring.str().c_str()) >= 0,
+ "regex: snprintf failed during match");
return result;
}
@@ -119,7 +123,7 @@ uw_Regex__FFI_regex uw_Regex__FFI_compile(uw_context* const context,
uw_register_transactional(context, result,
nullptr, nullptr, DeleteRegex) == 0,
"regex: could not register DeleteRegex finalizer");
- auto flags = std::regex_constants::extended;
+ auto flags = std::regex_constants::extended;
if (!case_sensitive) {
flags |= std::regex_constants::icase;
}
@@ -146,9 +150,13 @@ uw_Regex__FFI_match uw_Regex__FFI_do_match(uw_context* const context,
uw_Regex__FFI_match result;
// Make a duplicate of the string to match against, so if it goes out of
// scope in the calling Ur code, we still have it.
+ const auto haystack_length = std::strlen(haystack);
result.haystack =
- reinterpret_cast<char*>(uw_malloc(context, std::strlen(haystack)));
- std::strcpy(result.haystack, haystack);
+ reinterpret_cast<char*>(uw_malloc(context, haystack_length + 1));
+ Assert(context,
+ std::snprintf(result.haystack, haystack_length + 1, "%s",
+ haystack) >= 0,
+ "regex: snprintf failed during match");
// Allocate to store the match information.
auto* match_results = new std::cmatch;
Assert(context,
diff --git a/src/regex__FFI.h b/src/regex__FFI.h
index 9d6a2c2..7bb4739 100644
--- a/src/regex__FFI.h
+++ b/src/regex__FFI.h
@@ -11,8 +11,8 @@ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License. */
-#ifndef URWEB_REGEX__FFI_H
-#define URWEB_REGEX__FFI_H
+#ifndef URWEB_REGEX__FFI_H_ /* NOLINT(build/header_guard) */
+#define URWEB_REGEX__FFI_H_
#ifdef __cplusplus
extern "C" {
@@ -51,4 +51,4 @@ uw_Regex__FFI_match uw_Regex__FFI_do_match(struct uw_context*,
}
#endif
-#endif /* URWEB_REGEX__FFI_H */
+#endif /* URWEB_REGEX__FFI_H_ */ /* NOLINT(build/header_guard) */