From df40d8dfa451a559da3fe8a9f160e390ed8f3c9e Mon Sep 17 00:00:00 2001
From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Thu, 15 Oct 2020 15:21:18 +0000
Subject: [PATCH] os_win32.cpp: Fix removal of trailing blanks.

git-svn-id: https://svn.code.sf.net/p/smartmontools/code/trunk@5091 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 smartmontools/ChangeLog    | 4 ++++
 smartmontools/os_win32.cpp | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/smartmontools/ChangeLog b/smartmontools/ChangeLog
index c00bc1404..7ae4f9b8a 100644
--- a/smartmontools/ChangeLog
+++ b/smartmontools/ChangeLog
@@ -1,5 +1,9 @@
 $Id$
 
+2020-10-15  Christian Franke  <franke@computer.org>
+
+	os_win32.cpp: Fix removal of trailing blanks.
+
 2020-10-09  Christian Franke  <franke@computer.org>
 
 	scsiprint.cpp: Don't print 'Accumulated power on time' if no
diff --git a/smartmontools/os_win32.cpp b/smartmontools/os_win32.cpp
index c83fd6bb5..63e5ace6c 100644
--- a/smartmontools/os_win32.cpp
+++ b/smartmontools/os_win32.cpp
@@ -1081,7 +1081,8 @@ static int get_identify_from_device_property(HANDLE hdevice, ata_identify_device
   }
 
   if (data.desc.ProductIdOffset) {
-    while (i > 1 && model[i-2] == ' ') // Keep last blank from VendorId
+    // Keep only first trailing blank after VendorId
+    while (i > 0 && model[i-1] == ' ' && (i < 2 || model[i-2] == ' '))
       i--;
     // Ignore VendorId "ATA"
     if (i <= 4 && !strncmp(model, "ATA", 3) && (i == 3 || model[3] == ' '))
-- 
GitLab