From be4bdb0db10612e5eef01d5bc9e9b12ee780db43 Mon Sep 17 00:00:00 2001
From: ballen4705 <ballen4705@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Fri, 22 Nov 2002 16:26:46 +0000
Subject: [PATCH]   Allen: smartctl.  When raw Attribute value was 2^31 or
 larger, did   not print correctly.

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@316 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 sm5/CHANGELOG    |  5 ++++-
 sm5/VERSION      |  2 +-
 sm5/ataprint.c   | 16 ++++++++++++----
 sm5/ataprint.cpp | 16 ++++++++++++----
 4 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/sm5/CHANGELOG b/sm5/CHANGELOG
index 3b005fe91..805c3b3d6 100644
--- a/sm5/CHANGELOG
+++ b/sm5/CHANGELOG
@@ -1,6 +1,6 @@
 CHANGELOG for smartmontools
 
-$Id: CHANGELOG,v 1.55 2002/11/22 13:37:42 ballen4705 Exp $
+$Id: CHANGELOG,v 1.56 2002/11/22 16:26:45 ballen4705 Exp $
 
 Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net>
 
@@ -25,6 +25,9 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
 CURRENT RELEASE (see VERSION file in this directory):
 
+  Allen: smartctl.  When raw Attribute value was 2^31 or larger, did
+  not print correctly.
+
 smartmontools-5.0.46
 
   Allen: smartd: added smartd.conf Directives -T and -s.  The -T Directive
diff --git a/sm5/VERSION b/sm5/VERSION
index 9e5feb525..abac1ea7b 100644
--- a/sm5/VERSION
+++ b/sm5/VERSION
@@ -1 +1 @@
-46
+47
diff --git a/sm5/ataprint.c b/sm5/ataprint.c
index 5a2fb37ad..08e02549c 100644
--- a/sm5/ataprint.c
+++ b/sm5/ataprint.c
@@ -30,7 +30,7 @@
 #include "smartctl.h"
 #include "extern.h"
 
-const char *CVSid2="$Id: ataprint.c,v 1.44 2002/11/14 14:57:20 ballen4705 Exp $"
+const char *CVSid2="$Id: ataprint.c,v 1.45 2002/11/22 16:26:46 ballen4705 Exp $"
 CVSID1 CVSID2 CVSID3 CVSID6;
 
 // for passing global control variables
@@ -416,9 +416,17 @@ void PrintSmartAttribWithThres (struct ata_smart_values *data,
       
       // convert the six individual bytes to a long long (8 byte) integer
       rawvalue = 0;
-      for (j = 0 ; j < 6 ; j++)
-	rawvalue |= disk->raw[j] << (8*j) ;
-      
+      for (j=0; j<6; j++) {
+	// This looks a bit roundabout, but is necessary.  Don't
+	// succumb to the temptation to use raw[j]<<(8*j) since under
+	// the normal rules this will be promoted to the native type.
+	// On a 32 bit machine this might then overflow.
+	long long temp;
+	temp = disk->raw[j];
+	temp <<= 8*j;
+	rawvalue |= temp;
+      }
+
       // This switch statement is where we handle Raw attributes
       // that are stored in an unusual vendor-specific format,
       switch (disk->id){
diff --git a/sm5/ataprint.cpp b/sm5/ataprint.cpp
index eac4d660d..e15b52403 100644
--- a/sm5/ataprint.cpp
+++ b/sm5/ataprint.cpp
@@ -30,7 +30,7 @@
 #include "smartctl.h"
 #include "extern.h"
 
-const char *CVSid2="$Id: ataprint.cpp,v 1.44 2002/11/14 14:57:20 ballen4705 Exp $"
+const char *CVSid2="$Id: ataprint.cpp,v 1.45 2002/11/22 16:26:46 ballen4705 Exp $"
 CVSID1 CVSID2 CVSID3 CVSID6;
 
 // for passing global control variables
@@ -416,9 +416,17 @@ void PrintSmartAttribWithThres (struct ata_smart_values *data,
       
       // convert the six individual bytes to a long long (8 byte) integer
       rawvalue = 0;
-      for (j = 0 ; j < 6 ; j++)
-	rawvalue |= disk->raw[j] << (8*j) ;
-      
+      for (j=0; j<6; j++) {
+	// This looks a bit roundabout, but is necessary.  Don't
+	// succumb to the temptation to use raw[j]<<(8*j) since under
+	// the normal rules this will be promoted to the native type.
+	// On a 32 bit machine this might then overflow.
+	long long temp;
+	temp = disk->raw[j];
+	temp <<= 8*j;
+	rawvalue |= temp;
+      }
+
       // This switch statement is where we handle Raw attributes
       // that are stored in an unusual vendor-specific format,
       switch (disk->id){
-- 
GitLab