Skip to content

chore: change ato... to strto... #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ TokenResult GetTokenForIAM(ConnInfo* ci, BOOL useCache) {
return TR_FAILURE;
}

int port = atoi(ci->port);
int port = pg_atoi(ci->port);
if (port < 1) {
port = 5432; // set to default port.
}
Expand Down Expand Up @@ -1241,7 +1241,7 @@ void GetLimitlessServer(ConnInfo *ci) {
return;
}

int host_port = atoi(ci->port);
int host_port = pg_atoi(ci->port);
ci->limitless_enabled = 0;
char connect_string_encoded[MAX_CONNECT_STRING];
makeConnectString(connect_string_encoded, ci, MAX_CONNECT_STRING);
Expand Down
18 changes: 9 additions & 9 deletions dlg_specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,19 +720,19 @@ copyConnAttributes(ConnInfo *ci, const char *attribute, const char *value)
else if (stricmp(attribute, INI_SECRET_ID) == 0)
STRCPY_FIXED(ci->secret_id, value);
else if (stricmp(attribute, INI_LIMITLESS_ENABLED) == 0)
ci->limitless_enabled = atoi(value);
ci->limitless_enabled = pg_atoi(value);
else if (stricmp(attribute, INI_LIMITLESS_MODE) == 0)
STRCPY_FIXED(ci->limitless_mode, value);
else if (stricmp(attribute, INI_LIMITLESS_MONITOR_INTERVAL_MS) == 0)
ci->limitless_monitor_interval_ms = atoi(value);
ci->limitless_monitor_interval_ms = pg_atoi(value);
else if (stricmp(attribute, INI_LIMITLESS_SERVICE_ID) == 0)
STRCPY_FIXED(ci->limitless_service_id, value);
else if (stricmp(attribute, INI_LOGDIR) == 0)
STRCPY_FIXED(ci->log_dir, value);
else if (stricmp(attribute, INI_RDSLOGGINGENABLED) == 0)
ci->rds_logging_enabled = atoi(value);
ci->rds_logging_enabled = pg_atoi(value);
else if (stricmp(attribute, INI_RDSLOGTHRESHOLD) == 0)
ci->rds_log_threshold = atoi(value);
ci->rds_log_threshold = pg_atoi(value);
else if (stricmp(attribute, INI_READONLY) == 0 || stricmp(attribute, ABBR_READONLY) == 0)
STRCPY_FIXED(ci->onlyread, value);
else if (stricmp(attribute, INI_PROTOCOL) == 0 || stricmp(attribute, ABBR_PROTOCOL) == 0)
Expand Down Expand Up @@ -1323,21 +1323,21 @@ MYLOG(MIN_LOG_LEVEL, "drivername=%s\n", drivername);
if (SQLGetPrivateProfileString(DSN, INI_CLUSTER_ID, NULL_STRING, temp, sizeof(temp), ODBC_INI) > 0)
STRCPY_FIXED(ci->cluster_id, temp);
if (SQLGetPrivateProfileString(DSN, INI_ENABLE_CLUSTER_FAILOVER, NULL_STRING, temp, sizeof(temp), ODBC_INI) > 0)
ci->enable_failover = atoi(temp);
ci->enable_failover = pg_atoi(temp);
if (SQLGetPrivateProfileString(DSN, INI_FAILOVER_MODE, NULL_STRING, temp, sizeof(temp), ODBC_INI) > 0)
STRCPY_FIXED(ci->failover_mode, temp);
if (SQLGetPrivateProfileString(DSN, INI_FAILOVER_TIMEOUT, NULL_STRING, temp, sizeof(temp), ODBC_INI) > 0)
ci->failover_timeout = atoi(temp);
ci->failover_timeout = pg_atoi(temp);
if (SQLGetPrivateProfileString(DSN, INI_HOST_PATTERN, NULL_STRING, temp, sizeof(temp), ODBC_INI) > 0)
STRCPY_FIXED(ci->host_pattern, temp);
if (SQLGetPrivateProfileString(DSN, INI_IGNORE_TOPOLOGY_REQUEST_RATE, NULL_STRING, temp, sizeof(temp), ODBC_INI) > 0)
ci->ignore_topology_refresh = atoi(temp);
ci->ignore_topology_refresh = pg_atoi(temp);
if (SQLGetPrivateProfileString(DSN, INI_READER_STRATEGY, NULL_STRING, temp, sizeof(temp), ODBC_INI) > 0)
STRCPY_FIXED(ci->reader_host_selector_strategy, temp);
if (SQLGetPrivateProfileString(DSN, INI_TOPOLOGY_HIGH_REFRESH_RATE, NULL_STRING, temp, sizeof(temp), ODBC_INI) > 0)
ci->topology_high_refresh = atoi(temp);
ci->topology_high_refresh = pg_atoi(temp);
if (SQLGetPrivateProfileString(DSN, INI_TOPOLOGY_REFRESH_RATE, NULL_STRING, temp, sizeof(temp), ODBC_INI) > 0)
ci->topology_refresh = atoi(temp);
ci->topology_refresh = pg_atoi(temp);

/* Allow override of odbcinst.ini parameters here */
get_Ci_Drivers(DSN, ODBC_INI, &(ci->drivers));
Expand Down
8 changes: 8 additions & 0 deletions psqlodbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
#endif /* __GNUC__ || __IBMC__ */
#endif /* __INCLUDE_POSTGRES_FE_H__ */

/*
* safe string-to-number conversions
*/
#define pg_atoi(val) (int) strtol(val, NULL, 10)
#define pg_atof(val) strtod(val, NULL)
#define pg_atol(val) strtol(val, NULL, 10)
#define pg_atoll(val) strtoll(val, NULL, 10)

#ifdef _MIMALLOC_
#include <mimalloc.h>
#define pg_malloc mi_malloc
Expand Down