#include "access/htup_details.h"
#include "catalog/pg_type.h"
#include "common/jsonapi.h"
+#include "common/string.h"
#include "fmgr.h"
#include "funcapi.h"
#include "lib/stringinfo.h"
*/
if (*tpath[i] != '\0')
{
- long ind;
+ int ind;
char *endptr;
errno = 0;
- ind = strtol(tpath[i], &endptr, 10);
- if (*endptr == '\0' && errno == 0 && ind <= INT_MAX && ind >= INT_MIN)
- ipath[i] = (int) ind;
- else
+ ind = strtoint(tpath[i], &endptr, 10);
+ if (endptr == tpath[i] || *endptr != '\0' || errno != 0)
ipath[i] = INT_MIN;
+ else
+ ipath[i] = ind;
}
else
ipath[i] = INT_MIN;
}
else if (have_array)
{
- long lindex;
+ int lindex;
uint32 index;
char *indextext = TextDatumGetCString(path[i]);
char *endptr;
errno = 0;
- lindex = strtol(indextext, &endptr, 10);
- if (endptr == indextext || *endptr != '\0' || errno != 0 ||
- lindex > INT_MAX || lindex < INT_MIN)
+ lindex = strtoint(indextext, &endptr, 10);
+ if (endptr == indextext || *endptr != '\0' || errno != 0)
{
*isnull = true;
return PointerGetDatum(NULL);
nelements = JsonContainerSize(container);
- if (-lindex > nelements)
+ if (lindex == INT_MIN || -lindex > nelements)
{
*isnull = true;
return PointerGetDatum(NULL);
* end, the access index must be normalized by level.
*/
enum jbvType *tpath = palloc0((path_len - level) * sizeof(enum jbvType));
- long lindex;
JsonbValue newkey;
/*
{
char *c,
*badp;
+ int lindex;
if (path_nulls[i])
break;
*/
c = TextDatumGetCString(path_elems[i]);
errno = 0;
- lindex = strtol(c, &badp, 10);
- if (errno != 0 || badp == c || *badp != '\0' || lindex > INT_MAX ||
- lindex < INT_MIN)
+ lindex = strtoint(c, &badp, 10);
+ if (badp == c || *badp != '\0' || errno != 0)
{
/* text, an object is expected */
newkey.type = jbvString;
tpath[i - level] = jbvArray;
}
-
}
/* Insert an actual value for either an object or array */
if (level < path_len && !path_nulls[level])
{
char *c = TextDatumGetCString(path_elems[level]);
- long lindex;
char *badp;
errno = 0;
- lindex = strtol(c, &badp, 10);
- if (errno != 0 || badp == c || *badp != '\0' || lindex > INT_MAX ||
- lindex < INT_MIN)
+ idx = strtoint(c, &badp, 10);
+ if (badp == c || *badp != '\0' || errno != 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("path element at position %d is not an integer: \"%s\"",
level + 1, c)));
- idx = lindex;
}
else
idx = nelems;