From 178608c5f8524967fdd21c7f6be16a9dab1e4cc0 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Sat, 2 Aug 2014 22:16:17 +0200 Subject: [PATCH] Geoip: Make some natives UTF-8 safe. --- dlls/geoip/geoip_natives.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dlls/geoip/geoip_natives.cpp b/dlls/geoip/geoip_natives.cpp index 7a6bea6d..b1f010c7 100755 --- a/dlls/geoip/geoip_natives.cpp +++ b/dlls/geoip/geoip_natives.cpp @@ -114,7 +114,7 @@ static cell AMX_NATIVE_CALL amx_geoip_country(AMX *amx, cell *params) return 0; } - return MF_SetAmxString(amx, params[2], country, length >= params[3] ? params[3] : length); // TODO: make this utf8 safe. + return MF_SetAmxStringUTF8Char(amx, params[2], country, length, params[3] + 1); } // native geoip_city(const ip[], result[], len, id = -1); @@ -126,7 +126,7 @@ static cell AMX_NATIVE_CALL amx_geoip_city(AMX *amx, cell *params) const char *path[] = { "city", "names", getLang(params[4]), NULL }; const char *city = lookupString(ip, path, &length); - return MF_SetAmxString(amx, params[2], city ? city : "", length >= params[3] ? params[3] : length); // TODO: make this utf8 safe. + return MF_SetAmxStringUTF8Char(amx, params[2], city ? city : "", length, params[3] + 1); } // native geoip_region_code(const ip[], result[], len); @@ -160,7 +160,7 @@ static cell AMX_NATIVE_CALL amx_geoip_region_code(AMX *amx, cell *params) } } - return MF_SetAmxString(amx, params[2], finalLength ? code : "", finalLength >= params[3] ? params[3] : finalLength); + return MF_SetAmxString(amx, params[2], finalLength ? code : "", ke::Min(finalLength, params[3])); } // native geoip_region_name(const ip[], result[], len, id = -1); @@ -172,7 +172,7 @@ static cell AMX_NATIVE_CALL amx_geoip_region_name(AMX *amx, cell *params) const char *path[] = { "subdivisions", "0", "names", getLang(params[4]), NULL }; // First result. const char *region = lookupString(ip, path, &length); - return MF_SetAmxString(amx, params[2], region ? region : "", length >= params[3] ? params[3] : length); // TODO: make this utf8 safe. + return MF_SetAmxStringUTF8Char(amx, params[2], region ? region : "", length, params[3] + 1); } // native geoip_timezone(const ip[], result[], len); @@ -184,7 +184,7 @@ static cell AMX_NATIVE_CALL amx_geoip_timezone(AMX *amx, cell *params) const char *path[] = { "location", "time_zone", NULL }; const char *timezone = lookupString(ip, path, &length); - return MF_SetAmxString(amx, params[2], timezone ? timezone : "", length >= params[3] ? params[3] : length); + return MF_SetAmxString(amx, params[2], timezone ? timezone : "", ke::Min(length, params[3])); } // native geoip_latitude(const ip[]); @@ -247,7 +247,7 @@ static cell AMX_NATIVE_CALL amx_geoip_continent_name(AMX *amx, cell *params) const char *path[] = { "continent", "names", getLang(params[4]), NULL }; const char *continent = lookupString(ip, path, &length); - return MF_SetAmxString(amx, params[2], continent ? continent : "", length >= params[3] ? params[3] : length); // TODO: make this utf8 safe. + return MF_SetAmxStringUTF8Char(amx, params[2], continent ? continent : "", length, params[3] + 1); }