From b5f149476daff5a21696b384bcf0e4d5a4236b8c Mon Sep 17 00:00:00 2001 From: jsteube Date: Fri, 2 Jun 2017 10:08:19 +0200 Subject: [PATCH] Trim OpenCL device name whitespaces --- include/shared.h | 3 +++ src/opencl.c | 4 ++++ src/shared.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/include/shared.h b/include/shared.h index 0228b4293..a16f923cb 100644 --- a/include/shared.h +++ b/include/shared.h @@ -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 diff --git a/src/opencl.c b/src/opencl.c index d5fcd300c..bf5847702 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -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, ¶m_value_size); diff --git a/src/shared.c b/src/shared.c index 84ff85a0e..cd5438576 100644 --- a/src/shared.c +++ b/src/shared.c @@ -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; +}