]> granicus.if.org Git - postgresql/blobdiff - src/backend/utils/adt/mac8.c
Fix initialization of fake LSN for unlogged relations
[postgresql] / src / backend / utils / adt / mac8.c
index fe345743aefe04d33fb3c3df92e700da1d1dece7..0b1fe4978ea809bce38640de1cb13c0622f34cd8 100644 (file)
@@ -11,7 +11,7 @@
  * The following code is written with the assumption that the OUI field
  * size is 24 bits.
  *
- * Portions Copyright (c) 1998-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1998-2019, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
  *               src/backend/utils/adt/mac8.c
@@ -21,9 +21,9 @@
 
 #include "postgres.h"
 
-#include "access/hash.h"
 #include "libpq/pqformat.h"
 #include "utils/builtins.h"
+#include "utils/hashutils.h"
 #include "utils/inet.h"
 
 /*
@@ -35,9 +35,9 @@
 #define lobits(addr) \
   ((unsigned long)(((addr)->e<<24) | ((addr)->f<<16) | ((addr)->g<<8) | ((addr)->h)))
 
-static unsigned char hex2_to_uchar(const char *str, const char *ptr);
+static unsigned char hex2_to_uchar(const unsigned char *str, const unsigned char *ptr);
 
-static const char hexlookup[128] = {
+static const signed char hexlookup[128] = {
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -58,16 +58,16 @@ static const char hexlookup[128] = {
  * the entire string, which is used only for error reporting.
  */
 static inline unsigned char
-hex2_to_uchar(const char *ptr, const char *str)
+hex2_to_uchar(const unsigned char *ptr, const unsigned char *str)
 {
        unsigned char ret = 0;
-       char            lookup;
+       signed char lookup;
 
        /* Handle the first character */
-       if (*ptr < 0)
+       if (*ptr > 127)
                goto invalid_input;
 
-       lookup = hexlookup[(unsigned char) *ptr];
+       lookup = hexlookup[*ptr];
        if (lookup < 0)
                goto invalid_input;
 
@@ -76,10 +76,10 @@ hex2_to_uchar(const char *ptr, const char *str)
        /* Move to the second character */
        ptr++;
 
-       if (*ptr < 0)
+       if (*ptr > 127)
                goto invalid_input;
 
-       lookup = hexlookup[(unsigned char) *ptr];
+       lookup = hexlookup[*ptr];
        if (lookup < 0)
                goto invalid_input;
 
@@ -103,8 +103,8 @@ invalid_input:
 Datum
 macaddr8_in(PG_FUNCTION_ARGS)
 {
-       const char *str = PG_GETARG_CSTRING(0);
-       const char *ptr = str;
+       const unsigned char *str = (unsigned char *) PG_GETARG_CSTRING(0);
+       const unsigned char *ptr = str;
        macaddr8   *result;
        unsigned char a = 0,
                                b = 0,
@@ -115,10 +115,10 @@ macaddr8_in(PG_FUNCTION_ARGS)
                                g = 0,
                                h = 0;
        int                     count = 0;
-       char            spacer = '\0';
+       unsigned char spacer = '\0';
 
        /* skip leading spaces */
-       while (*ptr && isspace((unsigned char) *ptr))
+       while (*ptr && isspace(*ptr))
                ptr++;
 
        /* digits must always come in pairs */
@@ -163,8 +163,8 @@ macaddr8_in(PG_FUNCTION_ARGS)
                                /* must be trailing garbage... */
                                ereport(ERROR,
                                                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                               errmsg("invalid input syntax for type %s: \"%s\"", "macaddr8",
-                                          str)));
+                                                errmsg("invalid input syntax for type %s: \"%s\"", "macaddr8",
+                                                               str)));
                }
 
                /* Move forward to where the next byte should be */
@@ -181,8 +181,8 @@ macaddr8_in(PG_FUNCTION_ARGS)
                        else if (spacer != *ptr)
                                ereport(ERROR,
                                                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                               errmsg("invalid input syntax for type %s: \"%s\"", "macaddr8",
-                                          str)));
+                                                errmsg("invalid input syntax for type %s: \"%s\"", "macaddr8",
+                                                               str)));
 
                        /* move past the spacer */
                        ptr++;
@@ -191,9 +191,9 @@ macaddr8_in(PG_FUNCTION_ARGS)
                /* allow trailing whitespace after if we have 6 or 8 bytes */
                if (count == 6 || count == 8)
                {
-                       if (isspace((unsigned char) *ptr))
+                       if (isspace(*ptr))
                        {
-                               while (*++ptr && isspace((unsigned char) *ptr));
+                               while (*++ptr && isspace(*ptr));
 
                                /* If we found a space and then non-space, it's invalid */
                                if (*ptr)
@@ -218,8 +218,8 @@ macaddr8_in(PG_FUNCTION_ARGS)
        else if (count != 8)
                ereport(ERROR,
                                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                          errmsg("invalid input syntax for type %s: \"%s\"", "macaddr8",
-                                         str)));
+                                errmsg("invalid input syntax for type %s: \"%s\"", "macaddr8",
+                                               str)));
 
        result = (macaddr8 *) palloc0(sizeof(macaddr8));
 
@@ -407,6 +407,15 @@ hashmacaddr8(PG_FUNCTION_ARGS)
        return hash_any((unsigned char *) key, sizeof(macaddr8));
 }
 
+Datum
+hashmacaddr8extended(PG_FUNCTION_ARGS)
+{
+       macaddr8   *key = PG_GETARG_MACADDR8_P(0);
+
+       return hash_any_extended((unsigned char *) key, sizeof(macaddr8),
+                                                        PG_GETARG_INT64(1));
+}
+
 /*
  * Arithmetic functions: bitwise NOT, AND, OR.
  */
@@ -552,10 +561,10 @@ macaddr8tomacaddr(PG_FUNCTION_ARGS)
                ereport(ERROR,
                                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                                 errmsg("macaddr8 data out of range to convert to macaddr"),
-                          errhint("Only addresses that have FF and FE as values in the "
-                                          "4th and 5th bytes, from the left, for example: "
-                                        "XX-XX-XX-FF-FE-XX-XX-XX, are eligible to be converted "
-                                          "from macaddr8 to macaddr.")));
+                                errhint("Only addresses that have FF and FE as values in the "
+                                                "4th and 5th bytes from the left, for example "
+                                                "xx:xx:xx:ff:fe:xx:xx:xx, are eligible to be converted "
+                                                "from macaddr8 to macaddr.")));
 
        result->a = addr->a;
        result->b = addr->b;