aboutsummaryrefslogtreecommitdiff
path: root/contrib/pgcrypto/pgp-pgsql.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2020-12-21 09:37:11 +0900
committerMichael Paquier <michael@paquier.xyz>2020-12-21 09:37:11 +0900
commit93e8ff8701a65a70ea8826bdde7fdbbd9c285477 (patch)
tree70afa5868c3b27609fe50097204bba45a21092d6 /contrib/pgcrypto/pgp-pgsql.c
parent4e1ee79e3182256d9c8ddbc1ce9c4e8419c611ff (diff)
downloadpostgresql-93e8ff8701a65a70ea8826bdde7fdbbd9c285477.tar.gz
postgresql-93e8ff8701a65a70ea8826bdde7fdbbd9c285477.zip
Refactor logic to check for ASCII-only characters in string
The same logic was present for collation commands, SASLprep and pgcrypto, so this removes some code. Author: Michael Paquier Reviewed-by: Stephen Frost, Heikki Linnakangas Discussion: https://postgr.es/m/X9womIn6rne6Gud2@paquier.xyz
Diffstat (limited to 'contrib/pgcrypto/pgp-pgsql.c')
-rw-r--r--contrib/pgcrypto/pgp-pgsql.c18
1 files changed, 3 insertions, 15 deletions
diff --git a/contrib/pgcrypto/pgp-pgsql.c b/contrib/pgcrypto/pgp-pgsql.c
index 62a2f351e43..0536bfb8921 100644
--- a/contrib/pgcrypto/pgp-pgsql.c
+++ b/contrib/pgcrypto/pgp-pgsql.c
@@ -32,6 +32,7 @@
#include "postgres.h"
#include "catalog/pg_type.h"
+#include "common/string.h"
#include "funcapi.h"
#include "lib/stringinfo.h"
#include "mb/pg_wchar.h"
@@ -92,19 +93,6 @@ convert_to_utf8(text *src)
return convert_charset(src, GetDatabaseEncoding(), PG_UTF8);
}
-static bool
-string_is_ascii(const char *str)
-{
- const char *p;
-
- for (p = str; *p; p++)
- {
- if (IS_HIGHBIT_SET(*p))
- return false;
- }
- return true;
-}
-
static void
clear_and_pfree(text *p)
{
@@ -814,7 +802,7 @@ parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array,
v = TextDatumGetCString(key_datums[i]);
- if (!string_is_ascii(v))
+ if (!pg_is_ascii(v))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("header key must not contain non-ASCII characters")));
@@ -836,7 +824,7 @@ parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array,
v = TextDatumGetCString(val_datums[i]);
- if (!string_is_ascii(v))
+ if (!pg_is_ascii(v))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("header value must not contain non-ASCII characters")));