Tor 0.4.9.3-alpha-dev
Loading...
Searching...
No Matches
Macros | Functions
parse_int.c File Reference

Convert strings into the integers they encode, with bounds checking. More...

#include "lib/string/parse_int.h"
#include "lib/cc/compat_compiler.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Macros

#define CHECK_STRTOX_RESULT()
 

Functions

long tor_parse_long (const char *s, int base, long min, long max, int *ok, char **next)
 
unsigned long tor_parse_ulong (const char *s, int base, unsigned long min, unsigned long max, int *ok, char **next)
 
double tor_parse_double (const char *s, double min, double max, int *ok, char **next)
 
uint64_t tor_parse_uint64 (const char *s, int base, uint64_t min, uint64_t max, int *ok, char **next)
 

Detailed Description

Convert strings into the integers they encode, with bounds checking.

Definition in file parse_int.c.

Macro Definition Documentation

◆ CHECK_STRTOX_RESULT

#define CHECK_STRTOX_RESULT ( )
Value:
STMT_BEGIN \
/* Did an overflow occur? */ \
if (errno == ERANGE) \
goto err; \
/* Was at least one character converted? */ \
if (endptr == s) \
goto err; \
/* Were there unexpected unconverted characters? */ \
if (!next && *endptr) \
goto err; \
/* Illogical (max, min) inputs? */ \
if (max < min) \
goto err; \
/* Is r within limits? */ \
if (r < min || r > max) \
goto err; \
if (ok) *ok = 1; \
if (next) *next = endptr; \
return r; \
err: \
if (ok) *ok = 0; \
if (next) *next = endptr; \
return 0; \
STMT_END

Definition at line 20 of file parse_int.c.

Function Documentation

◆ tor_parse_double()

double tor_parse_double ( const char *  s,
double  min,
double  max,
int *  ok,
char **  next 
)

As tor_parse_long(), but return a double.

Definition at line 97 of file parse_int.c.

Referenced by config_parse_units(), parse_dir_authority_line(), and parse_dir_fallback_line().

◆ tor_parse_long()

long tor_parse_long ( const char *  s,
int  base,
long  min,
long  max,
int *  ok,
char **  next 
)

Extract a long from the start of s, in the given numeric base. If base is 0, s is parsed as a decimal, octal, or hex number in the syntax of a C integer literal. If there is unconverted data and next is provided, set *next to the first unconverted character. An error has occurred if no characters are converted; or if there are unconverted characters and next is NULL; or if the parsed value is not between min and max. When no error occurs, return the parsed value and set *ok (if provided) to

  1. When an error occurs, return 0 and set *ok (if provided) to 0.

Definition at line 59 of file parse_int.c.

Referenced by accounting_parse_options(), cmp_int_strings_(), compute_consensus_method(), connection_ap_process_natd(), dirvote_compute_params(), dirvote_get_intermediate_param_value(), do_main_loop(), entry_guard_parse_from_state(), get_net_param_from_list(), handle_cmdline_passphrase_fd(), handle_control_add_onion(), handle_control_protocolinfo(), hs_parse_port_config(), measured_bw_line_parse(), metrics_parse_ports(), networkstatus_parse_vote_from_string(), parse_dir_authority_line(), parse_dir_fallback_line(), parse_port_range(), parse_possibly_bad_iso_time(), parse_process_specifier(), port_parse_config(), rep_hist_load_mtbf_data(), router_parse_entry_from_string(), and tor_addr_port_split().

◆ tor_parse_uint64()

uint64_t tor_parse_uint64 ( const char *  s,
int  base,
uint64_t  min,
uint64_t  max,
int *  ok,
char **  next 
)

As tor_parse_long, but return a uint64_t. Only base 10 is guaranteed to work for now.

Definition at line 110 of file parse_int.c.

Referenced by buf_http_find_content_length(), bwhist_load_bwhist_state_section(), config_parse_units(), desc_decode_encrypted_v3(), desc_decode_plaintext_v3(), get_stream(), and sr_parse_srv().

◆ tor_parse_ulong()

unsigned long tor_parse_ulong ( const char *  s,
int  base,
unsigned long  min,
unsigned long  max,
int *  ok,
char **  next 
)