use safer functions, check error value

This commit is contained in:
Stanislav Malyshev 2007-02-17 01:45:52 +00:00
parent 704b191d6a
commit 05584eb55a

View file

@ -186,17 +186,20 @@ static PHP_FUNCTION(pspell_new)
* pointing to the location of the dictionaries * pointing to the location of the dictionaries
*/ */
if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) { if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) {
LONG result;
dwLen = sizeof(aspell_dir) - 1; dwLen = sizeof(aspell_dir) - 1;
RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen); result = RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
RegCloseKey(hkey); RegCloseKey(hkey);
strcpy(data_dir, aspell_dir); if(result == ERROR_SUCCESS) {
strcat(data_dir, "\\data"); strlcpy(data_dir, aspell_dir, sizeof(data_dir));
strcpy(dict_dir, aspell_dir); strlcat(data_dir, "\\data", sizeof(data_dir));
strcat(dict_dir, "\\dict"); strlcpy(dict_dir, aspell_dir, sizeof(dict_dir));
strlcat(dict_dir, "\\dict", sizeof(dict_dir));
pspell_config_replace(config, "data-dir", data_dir); pspell_config_replace(config, "data-dir", data_dir);
pspell_config_replace(config, "dict-dir", dict_dir); pspell_config_replace(config, "dict-dir", dict_dir);
} }
}
#endif #endif
convert_to_string_ex(language); convert_to_string_ex(language);
@ -291,17 +294,20 @@ static PHP_FUNCTION(pspell_new_personal)
* pointing to the location of the dictionaries * pointing to the location of the dictionaries
*/ */
if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) { if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) {
LONG result;
dwLen = sizeof(aspell_dir) - 1; dwLen = sizeof(aspell_dir) - 1;
RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen); result = RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
RegCloseKey(hkey); RegCloseKey(hkey);
strcpy(data_dir, aspell_dir); if(result == ERROR_SUCCESS) {
strcat(data_dir, "\\data"); strlcpy(data_dir, aspell_dir, sizeof(data_dir));
strcpy(dict_dir, aspell_dir); strlcat(data_dir, "\\data", sizeof(data_dir));
strcat(dict_dir, "\\dict"); strlcpy(dict_dir, aspell_dir, sizeof(dict_dir));
strlcat(dict_dir, "\\dict", sizeof(dict_dir));
pspell_config_replace(config, "data-dir", data_dir); pspell_config_replace(config, "data-dir", data_dir);
pspell_config_replace(config, "dict-dir", dict_dir); pspell_config_replace(config, "dict-dir", dict_dir);
} }
}
#endif #endif
convert_to_string_ex(personal); convert_to_string_ex(personal);
@ -649,17 +655,20 @@ static PHP_FUNCTION(pspell_config_create)
* pointing to the location of the dictionaries * pointing to the location of the dictionaries
*/ */
if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) { if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) {
LONG result;
dwLen = sizeof(aspell_dir) - 1; dwLen = sizeof(aspell_dir) - 1;
RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen); result = RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
RegCloseKey(hkey); RegCloseKey(hkey);
strcpy(data_dir, aspell_dir); if(result == ERROR_SUCCESS) {
strcat(data_dir, "\\data"); strlcpy(data_dir, aspell_dir, sizeof(data_dir));
strcpy(dict_dir, aspell_dir); strlcat(data_dir, "\\data", sizeof(data_dir));
strcat(dict_dir, "\\dict"); strlcpy(dict_dir, aspell_dir, sizeof(dict_dir));
strlcat(dict_dir, "\\dict", sizeof(dict_dir));
pspell_config_replace(config, "data-dir", data_dir); pspell_config_replace(config, "data-dir", data_dir);
pspell_config_replace(config, "dict-dir", dict_dir); pspell_config_replace(config, "dict-dir", dict_dir);
} }
}
#endif #endif
convert_to_string_ex(language); convert_to_string_ex(language);