* Parse and try to interpret "value" as an integer value, and if successful, * store it in *result, complaining if there is any trailing garbage or an * overflow. This allows any number of leading and trailing whitespaces. */
| 1866 | * overflow. This allows any number of leading and trailing whitespaces. |
| 1867 | */ |
| 1868 | static bool |
| 1869 | parse_int_param(const char *value, int *result, PGconn *conn, |
| 1870 | const char *context) |
| 1871 | { |
| 1872 | char *end; |
| 1873 | long numval; |
| 1874 | |
| 1875 | Assert(value != NULL); |
| 1876 | |
| 1877 | *result = 0; |
| 1878 | |
| 1879 | /* strtol(3) skips leading whitespaces */ |
| 1880 | errno = 0; |
| 1881 | numval = strtol(value, &end, 10); |
| 1882 | |
| 1883 | /* |
| 1884 | * If no progress was done during the parsing or an error happened, fail. |
| 1885 | * This tests properly for overflows of the result. |
| 1886 | */ |
| 1887 | if (value == end || errno != 0 || numval != (int) numval) |
| 1888 | goto error; |
| 1889 | |
| 1890 | /* |
| 1891 | * Skip any trailing whitespace; if anything but whitespace remains before |
| 1892 | * the terminating character, fail |
| 1893 | */ |
| 1894 | while (*end != '\0' && isspace((unsigned char) *end)) |
| 1895 | end++; |
| 1896 | |
| 1897 | if (*end != '\0') |
| 1898 | goto error; |
| 1899 | |
| 1900 | *result = numval; |
| 1901 | return true; |
| 1902 | |
| 1903 | error: |
| 1904 | appendPQExpBuffer(&conn->errorMessage, |
| 1905 | libpq_gettext("invalid integer value \"%s\" for connection option \"%s\"\n"), |
| 1906 | value, context); |
| 1907 | return false; |
| 1908 | } |
| 1909 | |
| 1910 | #ifndef WIN32 |
| 1911 | /* |
no test coverage detected