diff mbox

[2/4] Fix error introduced in a15f05f1b43d8e85d9a3f72a0a

Message ID 1453980511-1787-2-git-send-email-suraev@alumni.ntnu.no
State Rejected
Headers show

Commit Message

Suraev Jan. 28, 2016, 11:28 a.m. UTC
From: Max <msuraev@sysmocom.de>

The code in bitvec_*_field was incorrectly ported from C++.
This also affected bitvec_unhex which uses it.
---
 src/bitvec.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Holger Freyther Jan. 30, 2016, 9:35 a.m. UTC | #1
> On 28 Jan 2016, at 12:28, suraev@alumni.ntnu.no wrote:
> 

Dear Max,



> The code in bitvec_*_field was incorrectly ported from C++.

and this is why a good commit message is so important. I assumed you had
simply copied the code from the PCU to libosmocore. I had no indication
that you had to change the semantic as part of C++ -> C. It would have
been important to write the thoughts of how you dealt with the C++ reference
and converted it to C.

After looking at the PCU I think the change from reference to pass by value
is a dangerous decision.

	bitvec_write_field(vector, writeIndex, *pui8, no_of_bits);

The code will silently continue to compile and this is why I think the
signature of bitvec_write_field and bitvec_read_field needs to be a pointer
to not have a huge mess with the osmo_pcu code.

holger
diff mbox

Patch

diff --git a/src/bitvec.c b/src/bitvec.c
index 7254674..407dfc8 100644
--- a/src/bitvec.c
+++ b/src/bitvec.c
@@ -389,6 +389,7 @@  int bitvec_unhex(struct bitvec *bv, const char *src)
 			return 1;
 
 		bitvec_write_field(bv, write_index, val, 4);
+		write_index += 4;
 	}
 	return 0;
 }
@@ -407,7 +408,7 @@  uint64_t bitvec_read_field(struct bitvec *bv, unsigned int read_index, unsigned
 			ui |= ((uint64_t)1 << (len - i - 1));
 		bv->cur_bit++;
 	}
-	read_index += len;
+
 	return ui;
 }
 
@@ -425,8 +426,8 @@  int bitvec_write_field(struct bitvec *bv, unsigned int write_index, uint64_t val
 		if (rc)
 			return rc;
 	}
-	write_index += len;
-	return 0;
+
+	return write_index + len;
 }
 
 /*! @} */