Skip to content

Commit

Permalink
Merge branch 'Dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
rwxe committed Sep 30, 2023
2 parents e1aeac1 + 0e6a1ae commit ca8a7c4
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
[![Build Status](https://travis-ci.org/JohnCGriffin/overflow.png)](https://travis-ci.org/JohnCGriffin/overflow)
# overflow
Check for integer overflow in Golang arithmetic and type conversion.
### Install

*This is a special README before the PR is merged by the upstream.*

This repository forks from `johncgriffin/overflow` and adds overflow detection for unsigned
integer arithmetic and type conversions between integers.

It has been well tested and benchmarked, and passed the code security scan provided by
Github Workflow.

[![CodeQL](https://github.com/rwxe/overflow/actions/workflows/codeql.yml/badge.svg)](https://github.com/rwxe/overflow/actions/workflows/codeql.yml)

```sh
go get github.com/johncgriffin/overflow
go get github.com/rwxe/overflow
```
Note that because Go has no template types, the majority of repetitive code is
generated by overflow_template.sh. If you have to change an
algorithm, change it there and regenerate the Go code via:

In order to be compatible with the old code and keep the code simple and readable, the new
code still does not use generics, but uses templates to generate code. So the majority of
repetitive code is generated by `overflow_template.sh`.

If you have to change an algorithm, change it there and regenerate the Go code via:
```sh
go generate
```
Expand All @@ -19,18 +32,15 @@ package main

import "fmt"
import "math"
import "github.com/JohnCGriffin/overflow"
import "github.com/rwxe/overflow"

func main() {

addend := math.MaxInt64 - 5

for i := 0; i < 10; i++ {
sum, ok := overflow.Add(addend, i)
fmt.Printf("%v+%v -> (%v,%v)\n",
addend, i, sum, ok)
}

}
```
yields the output
Expand All @@ -46,7 +56,6 @@ yields the output
9223372036854775802+8 -> (0,false)
9223372036854775802+9 -> (0,false)
```

For (u)int types, provide (U)Add, (U)Sub, (U)Mul, (U)Div, (U)Quotient, etc.


Expand Down

0 comments on commit ca8a7c4

Please sign in to comment.