throw PDNSException("PacketReader::getName(): name is empty");
}
-static string txtEscape(const string &name)
+string txtEscape(const string &name)
{
string ret;
- char ebuf[5];
+ std::array<char, 5> ebuf{};
- for(char i : name) {
- if((unsigned char) i >= 127 || (unsigned char) i < 32) {
- snprintf(ebuf, sizeof(ebuf), "\\%03u", (unsigned char)i);
- ret += ebuf;
+ for (char letter : name) {
+ const unsigned uch = static_cast<unsigned char>(letter);
+ if (uch >= 127 || uch < 32) {
+ snprintf(ebuf.data(), ebuf.size(), "\\%03u", uch);
+ ret += ebuf.data();
}
- else if(i=='"' || i=='\\'){
+ else if (letter == '"' || letter == '\\'){
ret += '\\';
- ret += i;
+ ret += letter;
+ }
+ else {
+ ret += letter;
}
- else
- ret += i;
}
return ret;
}
uint32_t d_notyouroffset; // only 'moveOffset' can touch this
const uint32_t& d_offset; // look.. but don't touch
};
+
+string txtEscape(const string &name);
}
}
-// FIXME copied from dnsparser.cc, see #6010 and #3503 if you want a proper solution
-static string txtEscape(const string &name)
-{
- string ret;
- char ebuf[5];
-
- for(char i : name) {
- if((unsigned char) i >= 127 || (unsigned char) i < 32) {
- snprintf(ebuf, sizeof(ebuf), "\\%03u", (unsigned char)i);
- ret += ebuf;
- }
- else if(i=='"' || i=='\\'){
- ret += '\\';
- ret += i;
- }
- else
- ret += i;
- }
- return ret;
-}
-
void RecordTextWriter::xfrSVCBValueList(const vector<string> &val) {
bool shouldQuote{false};
vector<string> escaped;