forked from torproject/tor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract simple integer math into its own module
- Loading branch information
1 parent
3883338
commit 2cf033f
Showing
19 changed files
with
294 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
orconfig.h | ||
lib/cc/*.h | ||
lib/err/*.h | ||
lib/intmath/*.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* Copyright (c) 2003-2004, Roger Dingledine | ||
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. | ||
* Copyright (c) 2007-2018, The Tor Project, Inc. */ | ||
/* See LICENSE for licensing information */ | ||
|
||
#include "lib/intmath/addsub.h" | ||
#include "lib/cc/compat_compiler.h" | ||
|
||
/* Helper: safely add two uint32_t's, capping at UINT32_MAX rather | ||
* than overflow */ | ||
uint32_t | ||
tor_add_u32_nowrap(uint32_t a, uint32_t b) | ||
{ | ||
/* a+b > UINT32_MAX check, without overflow */ | ||
if (PREDICT_UNLIKELY(a > UINT32_MAX - b)) { | ||
return UINT32_MAX; | ||
} else { | ||
return a+b; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* Copyright (c) 2003-2004, Roger Dingledine | ||
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. | ||
* Copyright (c) 2007-2018, The Tor Project, Inc. */ | ||
/* See LICENSE for licensing information */ | ||
|
||
#ifndef TOR_INTMATH_ADDSUB_H | ||
#define TOR_INTMATH_ADDSUB_H | ||
|
||
#include "lib/cc/torint.h" | ||
|
||
uint32_t tor_add_u32_nowrap(uint32_t a, uint32_t b); | ||
|
||
#endif /* !defined(TOR_INTMATH_MULDIV_H) */ |
Oops, something went wrong.