Trim OpenCL device name whitespaces

pull/1271/head
jsteube 7 years ago
parent 0eb18b068f
commit b5f149476d

@ -56,4 +56,7 @@ bool hc_path_create (const char *path);
bool hc_string_is_digit (const char *s);
void hc_string_trim_trailing (char *s);
void hc_string_trim_leading (char *s);
#endif // _SHARED_H

@ -2596,6 +2596,10 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime)
device_param->device_name = device_name;
hc_string_trim_leading (device_param->device_name);
hc_string_trim_trailing (device_param->device_name);
// device_vendor
CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_VENDOR, 0, NULL, &param_value_size);

@ -421,3 +421,49 @@ u32 get_random_num (const u32 min, const u32 max)
#endif
}
void hc_string_trim_leading (char *s)
{
int skip = 0;
const int len = (int) strlen (s);
for (int i = 0; i < len; i++)
{
const int c = (const int) s[i];
if (isspace (c) == 0) break;
skip++;
}
if (skip == 0) return;
const int new_len = len - skip;
memmove (s, s + skip, new_len);
s[new_len] = 0;
}
void hc_string_trim_trailing (char *s)
{
int skip = 0;
const int len = (int) strlen (s);
for (int i = len - 1; i >= 0; i--)
{
const int c = (const int) s[i];
if (isspace (c) == 0) break;
skip++;
}
if (skip == 0) return;
const size_t new_len = len - skip;
s[new_len] = 0;
}

Loading…
Cancel
Save