Skip to content

Commit

Permalink
Merge pull request #428 from RoaringBitmap/document_validate
Browse files Browse the repository at this point in the history
documenting validation
  • Loading branch information
lemire authored Jun 11, 2024
2 parents e18a7ce + 20ee4df commit 487ae1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,20 @@ consider the following sample of code:
buf := new(bytes.Buffer)
size,err:=rb.WriteTo(buf)
if err != nil {
t.Errorf("Failed writing")
fmt.Println("Failed writing") // return or panic
}
newrb:= New()
size,err=newrb.ReadFrom(buf)
if err != nil {
t.Errorf("Failed reading")
fmt.Println("Failed reading") // return or panic
}
// if buf is an untrusted source, you should validate the result
// (this adds a bit of complexity but it is necessary for security)
if newrb.Validate() != nil {
fmt.Println("Failed validation") // return or panic
}
if ! rb.Equals(newrb) {
t.Errorf("Cannot retrieve serialized version")
fmt.Println("Cannot retrieve serialized version")
}
```

Expand Down
6 changes: 5 additions & 1 deletion example_roaring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func TestExample_roaring060(t *testing.T) {
if err != nil {
fmt.Println("Failed reading")
t.Errorf("Failed reading")

}
// if buf is an untrusted source, you should validate the result
// (this adds a bit of complexity but it is necessary for security)
if newrb.Validate() != nil {
fmt.Println("Failed validation")
}
if !rb1.Equals(newrb) {
fmt.Println("I did not get back to original bitmap?")
Expand Down

0 comments on commit 487ae1a

Please sign in to comment.