File: fix-off-by-one.diff

package info (click to toggle)
libbinio 1.4%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,264 kB
  • sloc: sh: 8,413; cpp: 937; makefile: 21
file content (55 lines) | stat: -rw-r--r-- 1,440 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Description: Add patch from upstream cvs to fix a off-by-one error in binstr.cpp
Origin: upstream, http://libbinio.cvs.sourceforge.net/viewvc/libbinio/libbinio/src/binstr.cpp?r1=1.3&r2=1.4&view=patch

--- libbinio-1.4+dfsg1.orig/src/binstr.cpp
+++ libbinio-1.4+dfsg1/src/binstr.cpp
@@ -14,7 +14,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * binstr.cpp - Binary I/O on standard C strings in memory
- * Copyright (C) 2003 Simon Peter <dn.tlp@gmx.net>
+ * Copyright (C) 2003, 2010 Simon Peter <dn.tlp@gmx.net>
  */
 
 #include "binstr.h"
@@ -35,12 +35,11 @@ void binsbase::seek(long p, Offset offs)
   switch(offs) {
   case Set: spos = data + p; break;
   case Add: spos += p; break;
-  case End: spos = data + length - 1 + p; break;
+  case End: spos = data + length + p; break;
   }
 
   // Seek before start of data
   if(spos < data) {
-    err |= Eof;
     spos = data;
     return;
   }
@@ -48,7 +47,7 @@ void binsbase::seek(long p, Offset offs)
   // Seek after end of data
   if(spos - data >= length) {
     err |= Eof;
-    spos = data + length - 1;
+    spos = data + length;
   }
 }
 
@@ -95,11 +94,12 @@ binosstream::~binosstream()
 
 void binosstream::putByte(Byte b)
 {
-  *spos = b;
-  spos++;
-
-  if(spos - data >= length)
-    spos = data + length - 1;
+  if(spos - data >= length) {
+    err |= Eof;
+  } else {
+    *spos = b;
+    spos++;
+  }
 }
 
 /***** binsstream *****/