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

avoid regexes to achieve gcc 4.8 compatibility #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
avoid regexes to achieve gcc 4.8 compatibility.
gcc/libstdc++ 4.8 (ships with Ubuntu 16.04) doesn't do regular expressions right. use a simple isdigit-based approach instead.
  • Loading branch information
woodpeck committed May 16, 2018
commit f9dc7e8afb7a34e613b9456709b9ae3423625fa6
11 changes: 5 additions & 6 deletions mod_log_ipmask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <array>
#include <cstdint>
#include <cstring>
#include <regex>
#include <sstream>
#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -720,8 +719,8 @@ static char const *set_default_ipv4_mask(cmd_parms *cmd, void *dummy,
log_ipmask_config *config = get_log_ipmask_config(cmd->server->module_config);
// We first validate the string. std::stoi would only report an error if it
// cannot convert the string, not if it contained extra characters.
if (!std::regex_match(arg, std::regex("[1-3]?[0-9]"))) {
return "Argument to LogDefaultIPv4Mask must be a number between zero and 32.";
for (auto p = arg; *p; p++) {
if (!isdigit(*p)) return "Argument to LogDefaultIPv4Mask must be a number between zero and 32.";
}
int mask_bits = std::atoi(arg);
if (mask_bits > 32) {
Expand All @@ -736,12 +735,12 @@ static char const *set_default_ipv6_mask(cmd_parms *cmd, void *dummy,
log_ipmask_config *config = get_log_ipmask_config(cmd->server->module_config);
// We first validate the string. std::stoi would only report an error if it
// cannot convert the string, not if it contained extra characters.
if (!std::regex_match(arg, std::regex("[1]?[0-9]?[0-9]"))) {
return "Argument to LogDefaultIPv4Mask must be a number between zero and 128.";
for (auto p = arg; *p; p++) {
if (!isdigit(*p)) return "Argument to LogDefaultIPv6Mask must be a number between zero and 32.";
}
int mask_bits = std::atoi(arg);
if (mask_bits > 128) {
return "Argument to LogDefaultIPv4Mask must be a number between zero and 128.";
return "Argument to LogDefaultIPv6Mask must be a number between zero and 128.";
}
config->masked_bits_ipv6 = mask_bits;
return nullptr;
Expand Down