From: Arvin Schnell Date: Thu, 22 Nov 2018 08:56:25 +0000 (+0100) Subject: - allow compiler to check format strings X-Git-Tag: v0.8.1~1^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dc72934471d1fee9feb4e45c4809e74702eb8e19;p=thirdparty%2Fsnapper.git - allow compiler to check format strings --- diff --git a/client/snapper.cc b/client/snapper.cc index 46240068..842bf6c9 100644 --- a/client/snapper.cc +++ b/client/snapper.cc @@ -807,7 +807,7 @@ help_delete() void filter_undeletables(ProxySnapshots& snapshots, vector& nums) { - auto filter = [&snapshots, &nums](ProxySnapshots::const_iterator undeletable, const string& message) + auto filter = [&snapshots, &nums](ProxySnapshots::const_iterator undeletable, const char* message) { if (undeletable == snapshots.end()) return; diff --git a/client/utils/text.cc b/client/utils/text.cc index e454110a..8610071d 100644 --- a/client/utils/text.cc +++ b/client/utils/text.cc @@ -14,12 +14,16 @@ using namespace std; -string _(const char* msgid) + +const char* +_(const char* msgid) { return dgettext("snapper", msgid); } -string _(const char* msgid, const char* msgid_plural, unsigned long int n) + +const char* +_(const char* msgid, const char* msgid_plural, unsigned long int n) { return dngettext("snapper", msgid, msgid_plural, n); } diff --git a/client/utils/text.h b/client/utils/text.h index d1f4d573..9e055f8b 100644 --- a/client/utils/text.h +++ b/client/utils/text.h @@ -11,8 +11,10 @@ #include #include -std::string _(const char* msgid); -std::string _(const char* msgid, const char* msgid_plural, unsigned long int n); +const char* _(const char* msgid) __attribute__ ((format_arg(1))); + +const char* _(const char* msgid, const char* msgid_plural, unsigned long int n) + __attribute__ ((format_arg(1))) __attribute__ ((format_arg(2))); /** Returns the column width of a multi-byte character string \a str */ unsigned mbs_width (const std::string & str); diff --git a/snapper/AppUtil.cc b/snapper/AppUtil.cc index 052235d5..1d8fb967 100644 --- a/snapper/AppUtil.cc +++ b/snapper/AppUtil.cc @@ -237,14 +237,14 @@ namespace snapper string - sformat(const string& format, ...) + sformat(const char* format, ...) { char* result; string str; va_list ap; va_start(ap, format); - if (vasprintf(&result, format.c_str(), ap) != -1) + if (vasprintf(&result, format, ap) != -1) { str = result; free(result); diff --git a/snapper/AppUtil.h b/snapper/AppUtil.h index d2211e77..75947a10 100644 --- a/snapper/AppUtil.h +++ b/snapper/AppUtil.h @@ -111,7 +111,7 @@ namespace snapper }; - string sformat(const string& format, ...); + string sformat(const char* format, ...) __attribute__ ((format(printf, 1, 2))); struct runtime_error_with_errno : public std::runtime_error