/* leave it up to the slow path to look for leading spaces */
if (*ptr == '-')
{
ptr++;
neg = true;
}
/* a leading '+' is uncommon so leave that for the slow path */
/* process the first digit */
digit = (*ptr - '0');
/* *Exploitunsignedarithmetictosavehavingtocheckboththeupperand *lowerboundsofthedigit.
*/ if (likely(digit < 10))
{
ptr++;
tmp = digit;
} else
{ /* we need at least one digit */ goto slow;
}
/* process remaining digits */ for (;;)
{
digit = (*ptr - '0');
if (digit >= 10) break;
ptr++;
if (unlikely(tmp > -(PG_INT16_MIN / 10))) goto out_of_range;
tmp = tmp * 10 + digit;
}
/* when the string does not end in a digit, let the slow path handle it */ if (unlikely(*ptr != '\0')) goto slow;
if (neg)
{ if (unlikely(pg_neg_u16_overflow(tmp, &result))) goto out_of_range; return result;
}
if (unlikely(tmp > PG_INT16_MAX)) goto out_of_range;
return (int16) tmp;
slow:
tmp = 0;
ptr = s; /* no need to reset neg */
/* skip leading spaces */ while (isspace((unsignedchar) *ptr))
ptr++;
for (;;)
{ if (*ptr >= '0' && *ptr <= '1')
{ if (unlikely(tmp > -(PG_INT16_MIN / 2))) goto out_of_range;
tmp = tmp * 2 + (*ptr++ - '0');
} elseif (*ptr == '_')
{ /* underscore must be followed by more digits */
ptr++; if (*ptr == '\0' || *ptr < '0' || *ptr > '1') goto invalid_syntax;
} else break;
}
} else
{
firstdigit = ptr;
for (;;)
{ if (*ptr >= '0' && *ptr <= '9')
{ if (unlikely(tmp > -(PG_INT16_MIN / 10))) goto out_of_range;
tmp = tmp * 10 + (*ptr++ - '0');
} elseif (*ptr == '_')
{ /* underscore may not be first */ if (unlikely(ptr == firstdigit)) goto invalid_syntax; /* and it must be followed by more digits */
ptr++; if (*ptr == '\0' || !isdigit((unsignedchar) *ptr)) goto invalid_syntax;
} else break;
}
}
/* require at least one digit */ if (unlikely(ptr == firstdigit)) goto invalid_syntax;
/* allow trailing whitespace, but not other trailing chars */ while (isspace((unsignedchar) *ptr))
ptr++;
if (unlikely(*ptr != '\0')) goto invalid_syntax;
if (neg)
{ if (unlikely(pg_neg_u16_overflow(tmp, &result))) goto out_of_range; return result;
}
if (tmp > PG_INT16_MAX) goto out_of_range;
return (int16) tmp;
out_of_range:
ereturn(escontext, 0,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value \"%s\" is out of range for type %s",
s, "smallint")));
invalid_syntax:
ereturn(escontext, 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"", "smallint", s)));
}
/* leave it up to the slow path to look for leading spaces */
if (*ptr == '-')
{
ptr++;
neg = true;
}
/* a leading '+' is uncommon so leave that for the slow path */
/* process the first digit */
digit = (*ptr - '0');
/* *Exploitunsignedarithmetictosavehavingtocheckboththeupperand *lowerboundsofthedigit.
*/ if (likely(digit < 10))
{
ptr++;
tmp = digit;
} else
{ /* we need at least one digit */ goto slow;
}
/* process remaining digits */ for (;;)
{
digit = (*ptr - '0');
if (digit >= 10) break;
ptr++;
if (unlikely(tmp > -(PG_INT32_MIN / 10))) goto out_of_range;
tmp = tmp * 10 + digit;
}
/* when the string does not end in a digit, let the slow path handle it */ if (unlikely(*ptr != '\0')) goto slow;
if (neg)
{ if (unlikely(pg_neg_u32_overflow(tmp, &result))) goto out_of_range; return result;
}
if (unlikely(tmp > PG_INT32_MAX)) goto out_of_range;
return (int32) tmp;
slow:
tmp = 0;
ptr = s; /* no need to reset neg */
/* skip leading spaces */ while (isspace((unsignedchar) *ptr))
ptr++;
for (;;)
{ if (*ptr >= '0' && *ptr <= '1')
{ if (unlikely(tmp > -(PG_INT32_MIN / 2))) goto out_of_range;
tmp = tmp * 2 + (*ptr++ - '0');
} elseif (*ptr == '_')
{ /* underscore must be followed by more digits */
ptr++; if (*ptr == '\0' || *ptr < '0' || *ptr > '1') goto invalid_syntax;
} else break;
}
} else
{
firstdigit = ptr;
for (;;)
{ if (*ptr >= '0' && *ptr <= '9')
{ if (unlikely(tmp > -(PG_INT32_MIN / 10))) goto out_of_range;
tmp = tmp * 10 + (*ptr++ - '0');
} elseif (*ptr == '_')
{ /* underscore may not be first */ if (unlikely(ptr == firstdigit)) goto invalid_syntax; /* and it must be followed by more digits */
ptr++; if (*ptr == '\0' || !isdigit((unsignedchar) *ptr)) goto invalid_syntax;
} else break;
}
}
/* require at least one digit */ if (unlikely(ptr == firstdigit)) goto invalid_syntax;
/* allow trailing whitespace, but not other trailing chars */ while (isspace((unsignedchar) *ptr))
ptr++;
if (unlikely(*ptr != '\0')) goto invalid_syntax;
if (neg)
{ if (unlikely(pg_neg_u32_overflow(tmp, &result))) goto out_of_range; return result;
}
if (tmp > PG_INT32_MAX) goto out_of_range;
return (int32) tmp;
out_of_range:
ereturn(escontext, 0,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value \"%s\" is out of range for type %s",
s, "integer")));
invalid_syntax:
ereturn(escontext, 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"", "integer", s)));
}
/* leave it up to the slow path to look for leading spaces */
if (*ptr == '-')
{
ptr++;
neg = true;
}
/* a leading '+' is uncommon so leave that for the slow path */
/* process the first digit */
digit = (*ptr - '0');
/* *Exploitunsignedarithmetictosavehavingtocheckboththeupperand *lowerboundsofthedigit.
*/ if (likely(digit < 10))
{
ptr++;
tmp = digit;
} else
{ /* we need at least one digit */ goto slow;
}
/* process remaining digits */ for (;;)
{
digit = (*ptr - '0');
if (digit >= 10) break;
ptr++;
if (unlikely(tmp > -(PG_INT64_MIN / 10))) goto out_of_range;
tmp = tmp * 10 + digit;
}
/* when the string does not end in a digit, let the slow path handle it */ if (unlikely(*ptr != '\0')) goto slow;
if (neg)
{ if (unlikely(pg_neg_u64_overflow(tmp, &result))) goto out_of_range; return result;
}
if (unlikely(tmp > PG_INT64_MAX)) goto out_of_range;
return (int64) tmp;
slow:
tmp = 0;
ptr = s; /* no need to reset neg */
/* skip leading spaces */ while (isspace((unsignedchar) *ptr))
ptr++;
for (;;)
{ if (*ptr >= '0' && *ptr <= '1')
{ if (unlikely(tmp > -(PG_INT64_MIN / 2))) goto out_of_range;
tmp = tmp * 2 + (*ptr++ - '0');
} elseif (*ptr == '_')
{ /* underscore must be followed by more digits */
ptr++; if (*ptr == '\0' || *ptr < '0' || *ptr > '1') goto invalid_syntax;
} else break;
}
} else
{
firstdigit = ptr;
for (;;)
{ if (*ptr >= '0' && *ptr <= '9')
{ if (unlikely(tmp > -(PG_INT64_MIN / 10))) goto out_of_range;
tmp = tmp * 10 + (*ptr++ - '0');
} elseif (*ptr == '_')
{ /* underscore may not be first */ if (unlikely(ptr == firstdigit)) goto invalid_syntax; /* and it must be followed by more digits */
ptr++; if (*ptr == '\0' || !isdigit((unsignedchar) *ptr)) goto invalid_syntax;
} else break;
}
}
/* require at least one digit */ if (unlikely(ptr == firstdigit)) goto invalid_syntax;
/* allow trailing whitespace, but not other trailing chars */ while (isspace((unsignedchar) *ptr))
ptr++;
if (unlikely(*ptr != '\0')) goto invalid_syntax;
if (neg)
{ if (unlikely(pg_neg_u64_overflow(tmp, &result))) goto out_of_range; return result;
}
if (tmp > PG_INT64_MAX) goto out_of_range;
return (int64) tmp;
out_of_range:
ereturn(escontext, 0,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value \"%s\" is out of range for type %s",
s, "bigint")));
invalid_syntax:
ereturn(escontext, 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"", "bigint", s)));
}
/* *strtoul()normallyonlysetsERANGE.Onsomesystemsitmayalsoset *EINVAL,whichsimplymeansitcouldn'tparsetheinputstring.Besure *toreportthatthesamewayasthestandarderrorindication(that *endptr==s).
*/ if ((errno && errno != ERANGE) || endptr == s)
ereturn(escontext, 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"",
typname, s)));
if (errno == ERANGE)
ereturn(escontext, 0,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value \"%s\" is out of range for type %s",
s, typname)));
if (endloc)
{ /* caller wants to deal with rest of string */
*endloc = endptr;
} else
{ /* allow only whitespace after number */ while (*endptr && isspace((unsignedchar) *endptr))
endptr++; if (*endptr)
ereturn(escontext, 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"",
typname, s)));
}
result = (uint32) cvt;
/* *Copewithpossibilitythatunsignedlongiswiderthanuint32,inwhich *casestrtoulwillnotraiseanerrorforsomevaluesthatareoutof *therangeofuint32. * *Forbackwardscompatibility,wewanttoacceptinputsthataregiven *withaminussign,soallowtheinputvalueifitmatchesaftereither *signedorunsignedextensiontolong. * *Toensureconsistentresultson32-bitand64-bitplatforms,makesure *theerrormessageisthesameasifstrtoul()hadreturnedERANGE.
*/ #if PG_UINT32_MAX != ULONG_MAX if (cvt != (unsignedlong) result &&
cvt != (unsignedlong) ((int) result))
ereturn(escontext, 0,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value \"%s\" is out of range for type %s",
s, typname))); #endif
/* *strtoul[l]normallyonlysetsERANGE.Onsomesystemsitmayalsoset *EINVAL,whichsimplymeansitcouldn'tparsetheinputstring.Besure *toreportthatthesamewayasthestandarderrorindication(that *endptr==s).
*/ if ((errno && errno != ERANGE) || endptr == s)
ereturn(escontext, 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"",
typname, s)));
if (errno == ERANGE)
ereturn(escontext, 0,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value \"%s\" is out of range for type %s",
s, typname)));
if (endloc)
{ /* caller wants to deal with rest of string */
*endloc = endptr;
} else
{ /* allow only whitespace after number */ while (*endptr && isspace((unsignedchar) *endptr))
endptr++; if (*endptr)
ereturn(escontext, 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"",
typname, s)));
}
return result;
}
/* *pg_itoa:convertsasigned16-bitintegertoitsstringrepresentation *andreturnsstrlen(a). * *Callermustensurethat'a'pointstoenoughmemorytoholdtheresult *(atleast7bytes,countingaleadingsignandtrailingNUL). * *Itdoesn'tseemworthimplementingthisseparately.
*/ int
pg_itoa(int16 i, char *a)
{ return pg_ltoa((int32) i, a);
}
/* *pg_ultoa_n:convertsanunsigned32-bitintegertoitsstringrepresentation, *notNUL-terminated,andreturnsthelengthofthatstringrepresentation * *Callermustensurethat'a'pointstoenoughmemorytoholdtheresult(at *least10bytes)
*/ int
pg_ultoa_n(uint32 value, char *a)
{ int olength,
i = 0;
/* Degenerate case */ if (value == 0)
{
*a = '0'; return1;
}
olength = decimalLength32(value);
/* Compute the result string. */ while (value >= 10000)
{ const uint32 c = value - 10000 * (value / 10000); const uint32 c0 = (c % 100) << 1; const uint32 c1 = (c / 100) << 1;
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.25Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.