[Libva] [PATCH V3 2/3] Use the strncasecmp instead of strcasecmp to make it more robust
Zhao Yakui
yakui.zhao at intel.com
Thu Sep 25 18:18:24 PDT 2014
At the same time the extra string arrary is removed.
Signed-off-by: Zhao Yakui <yakui.zhao at intel.com>
---
src/i965_device_info.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/i965_device_info.c b/src/i965_device_info.c
index 690d4e2..29757e2 100755
--- a/src/i965_device_info.c
+++ b/src/i965_device_info.c
@@ -430,13 +430,12 @@ const static char *hsw_cpu_hook_list[] = {
static void hsw_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
{
- char model_string[64], model_id[64];
+ char model_string[64];
char *model_ptr, *tmp_ptr;
int i, model_len, list_len;
bool found;
memset(model_string, 0, sizeof(model_string));
- memset(model_id, 0, sizeof(model_id));
/* If it can't detect cpu model_string, leave it alone */
if (intel_driver_detect_cpustring(model_string))
@@ -448,7 +447,7 @@ static void hsw_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *cod
*tmp_ptr = '\0';
/* strip the space character and convert to the lower case */
- model_ptr = model_id;
+ model_ptr = model_string;
model_len = strlen(model_string);
for (i = 0; i < model_len; i++) {
if (model_string[i] != ' ') {
@@ -460,9 +459,14 @@ static void hsw_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *cod
found = false;
list_len = sizeof(hsw_cpu_hook_list) / sizeof(char *);
+ model_len = strlen(model_string);
for (i = 0; i < list_len; i++) {
model_ptr = (char *)hsw_cpu_hook_list[i];
- if (strcasecmp(model_id, model_ptr) == 0) {
+
+ if (strlen(model_ptr) != model_len)
+ continue;
+
+ if (strncasecmp(model_string, model_ptr, model_len) == 0) {
found = true;
break;
}
--
1.7.10.1
More information about the Libva
mailing list