From: Otto Moerbeek Date: Wed, 5 Oct 2022 13:16:13 +0000 (+0200) Subject: Replace itoa() with std::to_string() X-Git-Tag: dnsdist-1.8.0-rc1~262^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=564db8c565decd49a55a9901eed39602cefa7dd3;p=thirdparty%2Fpdns.git Replace itoa() with std::to_string() --- diff --git a/.github/actions/spell-check/allow.txt b/.github/actions/spell-check/allow.txt index 1300aa6cff..bde902cd4e 100644 --- a/.github/actions/spell-check/allow.txt +++ b/.github/actions/spell-check/allow.txt @@ -3826,7 +3826,6 @@ uhi uhry uintptr uio -uitoa ulddquehrj ulen ulong diff --git a/modules/gmysqlbackend/smysql.cc b/modules/gmysqlbackend/smysql.cc index 8b3c80bbc5..a25f8f4c2c 100644 --- a/modules/gmysqlbackend/smysql.cc +++ b/modules/gmysqlbackend/smysql.cc @@ -562,7 +562,7 @@ void SMySQL::execute(const string& query) int err; if ((err = mysql_query(&d_db, query.c_str()))) - throw sPerrorException("Failed to execute mysql_query '" + query + "' Err=" + itoa(err)); + throw sPerrorException("Failed to execute mysql_query '" + query + "' Err=" + std::to_string(err)); } void SMySQL::startTransaction() diff --git a/modules/pipebackend/coprocess.cc b/modules/pipebackend/coprocess.cc index 92c15f23e9..ac2c350ee5 100644 --- a/modules/pipebackend/coprocess.cc +++ b/modules/pipebackend/coprocess.cc @@ -121,15 +121,15 @@ void CoProcess::checkStatus() int status; int ret = waitpid(d_pid, &status, WNOHANG); if (ret < 0) - throw PDNSException("Unable to ascertain status of coprocess " + itoa(d_pid) + " from " + itoa(getpid()) + ": " + string(strerror(errno))); + throw PDNSException("Unable to ascertain status of coprocess " + std::to_string(d_pid) + " from " + std::to_string(getpid()) + ": " + string(strerror(errno))); else if (ret) { if (WIFEXITED(status)) { int exitStatus = WEXITSTATUS(status); - throw PDNSException("Coprocess exited with code " + itoa(exitStatus)); + throw PDNSException("Coprocess exited with code " + std::to_string(exitStatus)); } if (WIFSIGNALED(status)) { int sig = WTERMSIG(status); - string reason = "CoProcess died on receiving signal " + itoa(sig); + string reason = "CoProcess died on receiving signal " + std::to_string(sig); #ifdef WCOREDUMP if (WCOREDUMP(status)) reason += ". Dumped core"; diff --git a/modules/pipebackend/pipebackend.cc b/modules/pipebackend/pipebackend.cc index 0f3dcbf5a9..fa94ea2f75 100644 --- a/modules/pipebackend/pipebackend.cc +++ b/modules/pipebackend/pipebackend.cc @@ -216,7 +216,7 @@ bool PipeBackend::list(const DNSName& target, int inZoneId, bool include_disable catch (PDNSException& ae) { g_log << Logger::Error << kBackendId << " Error from coprocess: " << ae.reason << endl; } - d_qname = DNSName(itoa(inZoneId)); // why do we store a number here?? + d_qname = DNSName(std::to_string(inZoneId)); // why do we store a number here?? return true; } diff --git a/modules/remotebackend/pipeconnector.cc b/modules/remotebackend/pipeconnector.cc index 5d563acc0a..e6f3a5da8e 100644 --- a/modules/remotebackend/pipeconnector.cc +++ b/modules/remotebackend/pipeconnector.cc @@ -187,15 +187,15 @@ bool PipeConnector::checkStatus() int status; int ret = waitpid(d_pid, &status, WNOHANG); if (ret < 0) - throw PDNSException("Unable to ascertain status of coprocess " + itoa(d_pid) + " from " + itoa(getpid()) + ": " + string(strerror(errno))); + throw PDNSException("Unable to ascertain status of coprocess " + std::to_string(d_pid) + " from " + std::to_string(getpid()) + ": " + string(strerror(errno))); else if (ret) { if (WIFEXITED(status)) { int exitStatus = WEXITSTATUS(status); - throw PDNSException("Coprocess exited with code " + itoa(exitStatus)); + throw PDNSException("Coprocess exited with code " + std::to_string(exitStatus)); } if (WIFSIGNALED(status)) { int sig = WTERMSIG(status); - string reason = "CoProcess died on receiving signal " + itoa(sig); + string reason = "CoProcess died on receiving signal " + std::to_string(sig); #ifdef WCOREDUMP if (WCOREDUMP(status)) reason += ". Dumped core"; diff --git a/pdns/arguments.cc b/pdns/arguments.cc index 739b404a38..7f9f9b558c 100644 --- a/pdns/arguments.cc +++ b/pdns/arguments.cc @@ -474,7 +474,7 @@ bool ArgvMap::parseFile(const char* fname, const string& arg, bool lax) string line; string pline; - ifstream configFileStream(fname); + std::ifstream configFileStream(fname); if (!configFileStream) { return false; } diff --git a/pdns/auth-main.cc b/pdns/auth-main.cc index f974da3002..0c4661c7d9 100644 --- a/pdns/auth-main.cc +++ b/pdns/auth-main.cc @@ -1113,7 +1113,7 @@ static int guardian(int argc, char** argv) // execute some kind of ping here if (DLQuitPlease()) takedown(1); // needs a parameter.. - setStatus("Child running on pid " + itoa(pid)); + setStatus("Child running on pid " + std::to_string(pid)); sleep(1); } } @@ -1130,7 +1130,7 @@ static int guardian(int argc, char** argv) g_log << Logger::Error << "Child requested a stop, exiting" << endl; exit(1); } - setStatus("Child died with code " + itoa(ret)); + setStatus("Child died with code " + std::to_string(ret)); g_log << Logger::Error << "Our pdns instance exited with code " << ret << ", respawning" << endl; sleep(1); @@ -1138,7 +1138,7 @@ static int guardian(int argc, char** argv) } if (WIFSIGNALED(status)) { int sig = WTERMSIG(status); - setStatus("Child died because of signal " + itoa(sig)); + setStatus("Child died because of signal " + std::to_string(sig)); g_log << Logger::Error << "Our pdns instance (" << pid << ") exited after signal " << sig << endl; #ifdef WCOREDUMP if (WCOREDUMP(status)) diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index 7e8c961cbb..bce52e8fbd 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -215,7 +215,7 @@ void GSQLBackend::setNotified(uint32_t domain_id, uint32_t serial) reset(); } catch(SSqlException &e) { - throw PDNSException("GSQLBackend unable to refresh domain_id "+itoa(domain_id)+": "+e.txtReason()); + throw PDNSException("GSQLBackend unable to refresh domain_id "+std::to_string(domain_id)+": "+e.txtReason()); } } @@ -227,7 +227,7 @@ void GSQLBackend::setLastCheck(uint32_t domain_id, time_t lastcheck) d_UpdateLastCheckOfZoneQuery_stmt->bind("last_check", lastcheck)->bind("domain_id", domain_id)->execute()->reset(); } catch (SSqlException &e) { - throw PDNSException("GSQLBackend unable to update last_check for domain_id " + itoa(domain_id) + ": " + e.txtReason()); + throw PDNSException("GSQLBackend unable to update last_check for domain_id " + std::to_string(domain_id) + ": " + e.txtReason()); } } @@ -730,7 +730,7 @@ bool GSQLBackend::updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName reset(); } catch(SSqlException &e) { - throw PDNSException("GSQLBackend unable to update ordername and auth for " + qname.toLogString() + " for domain_id "+itoa(domain_id)+", domain name '" + qname.toLogString() + "': "+e.txtReason()); + throw PDNSException("GSQLBackend unable to update ordername and auth for " + qname.toLogString() + " for domain_id "+std::to_string(domain_id)+", domain name '" + qname.toLogString() + "': "+e.txtReason()); } } else { try { @@ -746,7 +746,7 @@ bool GSQLBackend::updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName reset(); } catch(SSqlException &e) { - throw PDNSException("GSQLBackend unable to update ordername and auth for " + qname.toLogString() + "|" + QType(qtype).toString() + " for domain_id "+itoa(domain_id)+": "+e.txtReason()); + throw PDNSException("GSQLBackend unable to update ordername and auth for " + qname.toLogString() + "|" + QType(qtype).toString() + " for domain_id "+std::to_string(domain_id)+": "+e.txtReason()); } } } else { @@ -762,7 +762,7 @@ bool GSQLBackend::updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName reset(); } catch(SSqlException &e) { - throw PDNSException("GSQLBackend unable to nullify ordername and update auth for " + qname.toLogString() + " for domain_id "+itoa(domain_id)+": "+e.txtReason()); + throw PDNSException("GSQLBackend unable to nullify ordername and update auth for " + qname.toLogString() + " for domain_id "+std::to_string(domain_id)+": "+e.txtReason()); } } else { try { @@ -777,7 +777,7 @@ bool GSQLBackend::updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName reset(); } catch(SSqlException &e) { - throw PDNSException("GSQLBackend unable to nullify ordername and update auth for " + qname.toLogString() + "|" + QType(qtype).toString() + " for domain_id "+itoa(domain_id)+": "+e.txtReason()); + throw PDNSException("GSQLBackend unable to nullify ordername and update auth for " + qname.toLogString() + "|" + QType(qtype).toString() + " for domain_id "+std::to_string(domain_id)+": "+e.txtReason()); } } } @@ -796,7 +796,7 @@ bool GSQLBackend::updateEmptyNonTerminals(uint32_t domain_id, set& inse reset(); } catch (SSqlException &e) { - throw PDNSException("GSQLBackend unable to delete empty non-terminal records from domain_id "+itoa(domain_id)+": "+e.txtReason()); + throw PDNSException("GSQLBackend unable to delete empty non-terminal records from domain_id "+std::to_string(domain_id)+": "+e.txtReason()); } } else @@ -812,7 +812,7 @@ bool GSQLBackend::updateEmptyNonTerminals(uint32_t domain_id, set& inse reset(); } catch (SSqlException &e) { - throw PDNSException("GSQLBackend unable to delete empty non-terminal rr '"+qname.toLogString()+"' from domain_id "+itoa(domain_id)+": "+e.txtReason()); + throw PDNSException("GSQLBackend unable to delete empty non-terminal rr '"+qname.toLogString()+"' from domain_id "+std::to_string(domain_id)+": "+e.txtReason()); } } } @@ -830,7 +830,7 @@ bool GSQLBackend::updateEmptyNonTerminals(uint32_t domain_id, set& inse reset(); } catch (SSqlException &e) { - throw PDNSException("GSQLBackend unable to insert empty non-terminal rr '"+qname.toLogString()+"' in domain_id "+itoa(domain_id)+": "+e.txtReason()); + throw PDNSException("GSQLBackend unable to insert empty non-terminal rr '"+qname.toLogString()+"' in domain_id "+std::to_string(domain_id)+": "+e.txtReason()); } } @@ -866,7 +866,7 @@ bool GSQLBackend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qna d_afterOrderQuery_stmt->reset(); } catch(SSqlException &e) { - throw PDNSException("GSQLBackend unable to find before/after (after) for domain_id "+itoa(id)+" and qname '"+ qname.toLogString() +"': "+e.txtReason()); + throw PDNSException("GSQLBackend unable to find before/after (after) for domain_id "+std::to_string(id)+" and qname '"+ qname.toLogString() +"': "+e.txtReason()); } if(after.empty()) { @@ -884,7 +884,7 @@ bool GSQLBackend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qna d_firstOrderQuery_stmt->reset(); } catch(SSqlException &e) { - throw PDNSException("GSQLBackend unable to find before/after (first) for domain_id "+itoa(id)+" and qname '"+ qname.toLogString() + "': "+e.txtReason()); + throw PDNSException("GSQLBackend unable to find before/after (first) for domain_id "+std::to_string(id)+" and qname '"+ qname.toLogString() + "': "+e.txtReason()); } } @@ -911,7 +911,7 @@ bool GSQLBackend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qna d_beforeOrderQuery_stmt->reset(); } catch(SSqlException &e) { - throw PDNSException("GSQLBackend unable to find before/after (before) for domain_id "+itoa(id)+" and qname '"+ qname.toLogString() + ": "+e.txtReason()); + throw PDNSException("GSQLBackend unable to find before/after (before) for domain_id "+std::to_string(id)+" and qname '"+ qname.toLogString() + ": "+e.txtReason()); } if(! unhashed.empty()) @@ -939,7 +939,7 @@ bool GSQLBackend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qna d_lastOrderQuery_stmt->reset(); } catch(SSqlException &e) { - throw PDNSException("GSQLBackend unable to find before/after (last) for domain_id "+itoa(id)+" and qname '"+ qname.toLogString() + ": "+e.txtReason()); + throw PDNSException("GSQLBackend unable to find before/after (last) for domain_id "+std::to_string(id)+" and qname '"+ qname.toLogString() + ": "+e.txtReason()); } } else { before=qname; @@ -1755,7 +1755,7 @@ bool GSQLBackend::replaceRRSet(uint32_t domain_id, const DNSName& qname, const Q d_DeleteRRSetQuery_stmt-> bind("domain_id", domain_id)-> bind("qname", qname)-> - bind("qtype", "TYPE"+itoa(qt.getCode()))-> + bind("qtype", "TYPE"+std::to_string(qt.getCode()))-> execute()-> reset(); } diff --git a/pdns/bindparser.yy b/pdns/bindparser.yy index 9f8243fd9e..0b1056f2db 100644 --- a/pdns/bindparser.yy +++ b/pdns/bindparser.yy @@ -36,7 +36,7 @@ extern int linenumber; static void yyerror(const char *str) { extern char *current_filename; - throw PDNSException("Error in bind configuration '"+string(current_filename)+"' on line "+itoa(linenumber)+": "+str); + throw PDNSException("Error in bind configuration '"+string(current_filename)+"' on line "+std::to_string(linenumber)+": "+str); } extern FILE *yyin; diff --git a/pdns/dynhandler.cc b/pdns/dynhandler.cc index 64037a3ba2..b85d6969ab 100644 --- a/pdns/dynhandler.cc +++ b/pdns/dynhandler.cc @@ -336,8 +336,8 @@ string DLNotifyHandler(const vector&parts, Utility::pid_t ppid) } if (total != notified) - return itoa(notified)+" out of "+itoa(total)+" zones added to queue - see log"; - return "Added " + itoa(total) + " MASTER/SLAVE/PRODUCER/CONSUMER zones to queue"; + return std::to_string(notified)+" out of "+std::to_string(total)+" zones added to queue - see log"; + return "Added " + std::to_string(total) + " MASTER/SLAVE/PRODUCER/CONSUMER zones to queue"; } else { DNSName domain; try { diff --git a/pdns/misc.cc b/pdns/misc.cc index 3e98d332a0..7e5cb07063 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -507,20 +507,6 @@ std::string getCarbonHostName() return *hostname; } -string itoa(int i) -{ - ostringstream o; - o<second; } - return "TYPE" + itoa(code); + return "TYPE" + std::to_string(code); } uint16_t QType::chartocode(const char *p) diff --git a/pdns/resolver.cc b/pdns/resolver.cc index 836c345f05..be649e079b 100644 --- a/pdns/resolver.cc +++ b/pdns/resolver.cc @@ -204,7 +204,7 @@ namespace pdns { if(mdp.d_header.id != id) throw ResolverException("Remote nameserver replied with wrong id"); if(mdp.d_header.qdcount != 1) - throw ResolverException("resolver: received answer with wrong number of questions ("+itoa(mdp.d_header.qdcount)+")"); + throw ResolverException("resolver: received answer with wrong number of questions ("+std::to_string(mdp.d_header.qdcount)+")"); if(mdp.d_qname != origQname) throw ResolverException(string("resolver: received an answer to another question (")+mdp.d_qname.toLogString()+"!="+ origQname.toLogString()+".)"); } diff --git a/pdns/rfc2136handler.cc b/pdns/rfc2136handler.cc index 80b8fa3081..ffce117ad8 100644 --- a/pdns/rfc2136handler.cc +++ b/pdns/rfc2136handler.cc @@ -659,7 +659,7 @@ int PacketHandler::processUpdate(DNSPacket& p) { if (! ::arg().mustDo("dnsupdate")) return RCode::Refused; - string msgPrefix="UPDATE (" + itoa(p.d.id) + ") from " + p.getRemoteString() + " for " + p.qdomain.toLogString() + ": "; + string msgPrefix="UPDATE (" + std::to_string(p.d.id) + ") from " + p.getRemoteString() + " for " + p.qdomain.toLogString() + ": "; g_log<