Displaying 3 results from an estimated 3 matches for "ssize_min".
2019 Sep 23
0
Re: [PATCH nbdkit] server: public: Add nbdkit_parse_* functions for safely parsing integers.
...#if, but doesn't hurt to leave it in.
> +
> +int
> +nbdkit_parse_ssize_t (const char *what, const char *str, ssize_t *rp)
> +{
> + long long r;
> + char *end;
> +
> + errno = 0;
> + r = strtoll (str, &end, 0);
> +#if SSIZE_MAX != LONGLONG_MAX
> +#ifndef SSIZE_MIN
> +#define SSIZE_MIN (-SSIZE_MAX-1)
Assumes twos-complement, but that's sane enough for the platforms we target.
> +#endif
> + if (r < SSIZE_MIN || r > SSIZE_MAX)
> + errno = ERANGE;
> +#endif
> + PARSE_COMMON_TAIL;
> +}
> +
> +/* Functions for parsing un...
2019 Sep 21
2
[PATCH nbdkit] server: public: Add nbdkit_parse_* functions for safely parsing integers.
...if (r < INT64_MIN || r > INT64_MAX)
+ errno = ERANGE;
+#endif
+ PARSE_COMMON_TAIL;
+}
+
+int
+nbdkit_parse_ssize_t (const char *what, const char *str, ssize_t *rp)
+{
+ long long r;
+ char *end;
+
+ errno = 0;
+ r = strtoll (str, &end, 0);
+#if SSIZE_MAX != LONGLONG_MAX
+#ifndef SSIZE_MIN
+#define SSIZE_MIN (-SSIZE_MAX-1)
+#endif
+ if (r < SSIZE_MIN || r > SSIZE_MAX)
+ errno = ERANGE;
+#endif
+ PARSE_COMMON_TAIL;
+}
+
+/* Functions for parsing unsigned integers. */
+
+/* strtou* functions have surprising behaviour if the first character
+ * (after whitespace) is '-...
2019 Sep 23
2
Re: [PATCH nbdkit] server: public: Add nbdkit_parse_* functions for safely parsing integers.
...< INT_MIN || r > INT_MAX)
> > + errno = ERANGE;
> > +#endif
> > + PARSE_COMMON_TAIL;
> > +}
>
> Looks correct.
I actually compiled this and ran the tests with -m32 and -m64. It
took several rounds to get it right.
> > +#endif
> > + if (r < SSIZE_MIN || r > SSIZE_MAX)
> > + errno = ERANGE;
> > +#endif
> > + PARSE_COMMON_TAIL;
> > +}
> > +
> > +/* Functions for parsing unsigned integers. */
> > +
> > +/* strtou* functions have surprising behaviour if the first character
> > + * (after...