mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-25 12:00:31 +00:00
Fix bugs and make code tinier
- Fixed bug where stdio eof wasn't being sticky - Fixed bug where fseeko() wasn't clearing eof state - Removed assert() usage from libc favoring _unassert() / _npassert()
This commit is contained in:
parent
9b7c8db846
commit
d5910e2673
115 changed files with 510 additions and 290 deletions
5
third_party/dlmalloc/dlmalloc.c
vendored
5
third_party/dlmalloc/dlmalloc.c
vendored
|
@ -28,17 +28,20 @@
|
|||
#define USE_LOCKS 2
|
||||
#define MORECORE_CONTIGUOUS 0
|
||||
#define MALLOC_INSPECT_ALL 1
|
||||
#define ABORT_ON_ASSERT_FAILURE 0
|
||||
|
||||
#if IsTiny()
|
||||
#define INSECURE 1
|
||||
#define PROCEED_ON_ERROR 1
|
||||
#define ABORT_ON_ASSERT_FAILURE 0
|
||||
#endif
|
||||
|
||||
#if IsModeDbg()
|
||||
#define DEBUG 1
|
||||
#endif
|
||||
|
||||
#undef assert
|
||||
#define assert(x) _npassert(x)
|
||||
|
||||
#include "third_party/dlmalloc/platform.inc"
|
||||
#include "third_party/dlmalloc/locks.inc"
|
||||
#include "third_party/dlmalloc/chunks.inc"
|
||||
|
|
4
third_party/dlmalloc/platform.inc
vendored
4
third_party/dlmalloc/platform.inc
vendored
|
@ -200,10 +200,6 @@
|
|||
#endif /* LACKS_ERRNO_H */
|
||||
#ifdef DEBUG
|
||||
#if ABORT_ON_ASSERT_FAILURE
|
||||
#undef assert
|
||||
#define assert(x) if(!(x)) ABORT
|
||||
#else /* ABORT_ON_ASSERT_FAILURE */
|
||||
#include <assert.h>
|
||||
#endif /* ABORT_ON_ASSERT_FAILURE */
|
||||
#else /* DEBUG */
|
||||
#ifndef assert
|
||||
|
|
4
third_party/double-conversion/README.cosmo
vendored
4
third_party/double-conversion/README.cosmo
vendored
|
@ -11,3 +11,7 @@ ORIGIN
|
|||
LICENSE
|
||||
|
||||
BSD 3-Clause License
|
||||
|
||||
LOCAL CHANGES
|
||||
|
||||
- Use _unassert() macro for undefined behavior on failed assertions
|
||||
|
|
|
@ -28,6 +28,8 @@ THIRD_PARTY_DOUBLECONVERSION_TEST_BINS = \
|
|||
$(THIRD_PARTY_DOUBLECONVERSION_TEST_COMS) \
|
||||
$(THIRD_PARTY_DOUBLECONVERSION_TEST_COMS:%=%.dbg)
|
||||
|
||||
THIRD_PARTY_DOUBLECONVERSION_ARTIFACTS += THIRD_PARTY_DOUBLECONVERSION_TEST_A
|
||||
|
||||
THIRD_PARTY_DOUBLECONVERSION_TEST_A_SRCS_CC = \
|
||||
third_party/double-conversion/test/cctest.cc \
|
||||
third_party/double-conversion/test/gay-fixed.cc \
|
||||
|
@ -52,6 +54,10 @@ THIRD_PARTY_DOUBLECONVERSION_TEST_A_HDRS = \
|
|||
third_party/double-conversion/test/gay-shortest.h \
|
||||
third_party/double-conversion/test/gay-shortest-single.h
|
||||
|
||||
THIRD_PARTY_DOUBLECONVERSION_TEST_A_SRCS = \
|
||||
$(THIRD_PARTY_DOUBLECONVERSION_TEST_A_SRCS_C) \
|
||||
$(THIRD_PARTY_DOUBLECONVERSION_TEST_A_SRCS_CC)
|
||||
|
||||
THIRD_PARTY_DOUBLECONVERSION_A_OBJS = \
|
||||
$(THIRD_PARTY_DOUBLECONVERSION_A_SRCS_C:%.c=o/$(MODE)/%.o) \
|
||||
$(THIRD_PARTY_DOUBLECONVERSION_A_SRCS_CC:%.cc=o/$(MODE)/%.o)
|
||||
|
|
3
third_party/double-conversion/test/cctest.cc
vendored
3
third_party/double-conversion/test/cctest.cc
vendored
|
@ -24,9 +24,6 @@
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libc/isystem/stdio.h"
|
||||
#include "libc/isystem/stdlib.h"
|
||||
#include "libc/isystem/string.h"
|
||||
#include "third_party/double-conversion/test/cctest.h"
|
||||
// clang-format off
|
||||
|
||||
|
|
2
third_party/double-conversion/test/cctest.h
vendored
2
third_party/double-conversion/test/cctest.h
vendored
|
@ -26,8 +26,6 @@
|
|||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef CCTEST_H_
|
||||
#define CCTEST_H_
|
||||
#include "libc/isystem/stdio.h"
|
||||
#include "libc/isystem/string.h"
|
||||
#include "third_party/double-conversion/utils.h"
|
||||
// clang-format off
|
||||
|
||||
|
|
1
third_party/double-conversion/test/checks.h
vendored
1
third_party/double-conversion/test/checks.h
vendored
|
@ -26,7 +26,6 @@
|
|||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef V8_CHECKS_H_
|
||||
#define V8_CHECKS_H_
|
||||
#include "libc/isystem/string.h"
|
||||
#include "third_party/double-conversion/test/flags.h"
|
||||
// clang-format off
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libc/isystem/stdlib.h"
|
||||
#include "third_party/double-conversion/bignum-dtoa.h"
|
||||
#include "third_party/double-conversion/ieee.h"
|
||||
#include "third_party/double-conversion/test/cctest.h"
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libc/isystem/stdlib.h"
|
||||
#include "libc/isystem/string.h"
|
||||
#include "third_party/double-conversion/bignum.h"
|
||||
#include "third_party/double-conversion/test/cctest.h"
|
||||
#include "third_party/double-conversion/utils.h"
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libc/isystem/string.h"
|
||||
#include "third_party/double-conversion/double-conversion.h"
|
||||
#include "third_party/double-conversion/ieee.h"
|
||||
#include "third_party/double-conversion/test/cctest.h"
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libc/isystem/stdlib.h"
|
||||
#include "third_party/double-conversion/diy-fp.h"
|
||||
#include "third_party/double-conversion/test/cctest.h"
|
||||
#include "third_party/double-conversion/utils.h"
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libc/isystem/stdlib.h"
|
||||
#include "third_party/double-conversion/double-conversion.h"
|
||||
#include "third_party/double-conversion/ieee.h"
|
||||
#include "third_party/double-conversion/test/cctest.h"
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libc/isystem/stdlib.h"
|
||||
#include "third_party/double-conversion/diy-fp.h"
|
||||
#include "third_party/double-conversion/fast-dtoa.h"
|
||||
#include "third_party/double-conversion/ieee.h"
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libc/isystem/stdlib.h"
|
||||
#include "third_party/double-conversion/fixed-dtoa.h"
|
||||
#include "third_party/double-conversion/ieee.h"
|
||||
#include "third_party/double-conversion/test/cctest.h"
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libc/isystem/stdlib.h"
|
||||
#include "third_party/double-conversion/diy-fp.h"
|
||||
#include "third_party/double-conversion/ieee.h"
|
||||
#include "third_party/double-conversion/test/cctest.h"
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libc/isystem/stdlib.h"
|
||||
#include "third_party/double-conversion/bignum.h"
|
||||
#include "third_party/double-conversion/diy-fp.h"
|
||||
#include "third_party/double-conversion/ieee.h"
|
||||
|
|
4
third_party/double-conversion/utils.h
vendored
4
third_party/double-conversion/utils.h
vendored
|
@ -9,7 +9,11 @@
|
|||
#include "third_party/libcxx/cstring"
|
||||
// clang-format off
|
||||
|
||||
// [jart] use undefined behaavior to make code tinier
|
||||
// use ubsan build mode to troubleshoot errors
|
||||
#define DOUBLE_CONVERSION_ASSERT(x) _unassert(x)
|
||||
#define DOUBLE_CONVERSION_UNREACHABLE() unreachable
|
||||
#define DOUBLE_CONVERSION_UNIMPLEMENTED() notpossible
|
||||
|
||||
// Use DOUBLE_CONVERSION_NON_PREFIXED_MACROS to get unprefixed macros as was
|
||||
// the case in double-conversion releases prior to 3.1.6
|
||||
|
|
6
third_party/linenoise/linenoise.c
vendored
6
third_party/linenoise/linenoise.c
vendored
|
@ -588,7 +588,7 @@ static size_t GetMonospaceWidth(const char *p, size_t n, char *out_haswides) {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
if (out_haswides) {
|
||||
|
@ -1558,7 +1558,7 @@ static void linenoiseEditTranspose(struct linenoiseState *l) {
|
|||
p = q = malloc(c - a);
|
||||
p = mempcpy(p, l->buf + b, c - b);
|
||||
p = mempcpy(p, l->buf + a, b - a);
|
||||
assert(p - q == c - a);
|
||||
_unassert(p - q == c - a);
|
||||
memcpy(l->buf + a, q, p - q);
|
||||
l->pos = c;
|
||||
free(q);
|
||||
|
@ -1579,7 +1579,7 @@ static void linenoiseEditTransposeWords(struct linenoiseState *l) {
|
|||
p = mempcpy(p, l->buf + yi, yj - yi);
|
||||
p = mempcpy(p, l->buf + xj, yi - xj);
|
||||
p = mempcpy(p, l->buf + xi, xj - xi);
|
||||
assert(p - q == yj - xi);
|
||||
_unassert(p - q == yj - xi);
|
||||
memcpy(l->buf + xi, q, p - q);
|
||||
l->pos = yj;
|
||||
free(q);
|
||||
|
|
4
third_party/lua/lauxlib.h
vendored
4
third_party/lua/lauxlib.h
vendored
|
@ -1,5 +1,6 @@
|
|||
#ifndef lauxlib_h
|
||||
#define lauxlib_h
|
||||
#include "libc/assert.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "third_party/lua/lua.h"
|
||||
#include "third_party/lua/luaconf.h"
|
||||
|
@ -156,10 +157,9 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
|
|||
#if !defined(lua_assert)
|
||||
|
||||
#if defined LUAI_ASSERT
|
||||
#include <assert.h>
|
||||
#define lua_assert(c) assert(c)
|
||||
#else
|
||||
#define lua_assert(c) ((void)0)
|
||||
#define lua_assert(c) _unassert(c)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
2
third_party/lua/lua.mk
vendored
2
third_party/lua/lua.mk
vendored
|
@ -250,7 +250,7 @@ o/$(MODE)/third_party/lua/lua.com.dbg: \
|
|||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/third_party/lua/lua.com: \
|
||||
o/$(MODE)/third_party/lua/lua2.com: \
|
||||
o/$(MODE)/third_party/lua/lua.com.dbg \
|
||||
o/$(MODE)/third_party/zip/zip.com \
|
||||
o/$(MODE)/tool/build/symtab.com
|
||||
|
|
4
third_party/maxmind/maxminddb.c
vendored
4
third_party/maxmind/maxminddb.c
vendored
|
@ -16,13 +16,13 @@
|
|||
│ limitations under the License. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/inttypes.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
@ -686,7 +686,7 @@ static record_info_s record_info_for_database(const MMDB_s *const mmdb) {
|
|||
record_info.right_record_getter = &get_uint32;
|
||||
record_info.right_record_offset = 4;
|
||||
} else {
|
||||
assert(false);
|
||||
unreachable;
|
||||
}
|
||||
return record_info;
|
||||
}
|
||||
|
|
8
third_party/mbedtls/bignum.c
vendored
8
third_party/mbedtls/bignum.c
vendored
|
@ -15,14 +15,10 @@
|
|||
│ See the License for the specific language governing permissions and │
|
||||
│ limitations under the License. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/bswap.h"
|
||||
#include "libc/log/backtrace.internal.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/intrin/bsf.h"
|
||||
#include "libc/intrin/bswap.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nexgen32e/nexgen32e.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
2
third_party/mbedtls/bigshift.c
vendored
2
third_party/mbedtls/bigshift.c
vendored
|
@ -15,8 +15,6 @@
|
|||
│ See the License for the specific language governing permissions and │
|
||||
│ limitations under the License. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/mbedtls/bignum.h"
|
||||
|
|
25
third_party/mbedtls/ecp256.c
vendored
25
third_party/mbedtls/ecp256.c
vendored
|
@ -16,10 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/mbedtls/bignum_internal.h"
|
||||
|
@ -261,7 +258,7 @@ mbedtls_p256_add( uint64_t X[5],
|
|||
ADC( X[3], A[3], B[3], c, X[4] );
|
||||
#endif
|
||||
mbedtls_p256_rum( X );
|
||||
DCHECK_EQ( 0, X[4] );
|
||||
MBEDTLS_ASSERT( 0 == X[4] );
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -298,7 +295,7 @@ mbedtls_p256_sub( uint64_t X[5],
|
|||
#endif
|
||||
while( (int64_t)X[4] < 0 )
|
||||
mbedtls_p256_gro( X );
|
||||
DCHECK_EQ( 0, X[4] );
|
||||
MBEDTLS_ASSERT( 0 == X[4] );
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -322,7 +319,7 @@ mbedtls_p256_hub( uint64_t A[5],
|
|||
: "rax", "rcx", "memory", "cc");
|
||||
while( (int64_t)A[4] < 0 )
|
||||
mbedtls_p256_gro( A );
|
||||
DCHECK_EQ( 0, A[4] );
|
||||
MBEDTLS_ASSERT( 0 == A[4] );
|
||||
#else
|
||||
mbedtls_p256_sub( A, A, B );
|
||||
#endif
|
||||
|
@ -368,9 +365,9 @@ int mbedtls_p256_double_jac( const mbedtls_ecp_group *G,
|
|||
s.Xn = mbedtls_mpi_limbs( &P->X );
|
||||
s.Yn = mbedtls_mpi_limbs( &P->Y );
|
||||
s.Zn = mbedtls_mpi_limbs( &P->Z );
|
||||
CHECK_LE( s.Xn, 4 );
|
||||
CHECK_LE( s.Yn, 4 );
|
||||
CHECK_LE( s.Zn, 4 );
|
||||
MBEDTLS_ASSERT( s.Xn <= 4 );
|
||||
MBEDTLS_ASSERT( s.Yn <= 4 );
|
||||
MBEDTLS_ASSERT( s.Zn <= 4 );
|
||||
memcpy( s.X, P->X.p, s.Xn * 8 );
|
||||
memcpy( s.Y, P->Y.p, s.Yn * 8 );
|
||||
memcpy( s.Z, P->Z.p, s.Zn * 8 );
|
||||
|
@ -424,11 +421,11 @@ int mbedtls_p256_add_mixed( const mbedtls_ecp_group *G,
|
|||
s.Zn = mbedtls_mpi_limbs( &P->Z );
|
||||
s.QXn = mbedtls_mpi_limbs( &Q->X );
|
||||
s.QYn = mbedtls_mpi_limbs( &Q->Y );
|
||||
CHECK_LE( s.Xn, 4 );
|
||||
CHECK_LE( s.Yn, 4 );
|
||||
CHECK_LE( s.Zn, 4 );
|
||||
CHECK_LE( s.QXn, 4 );
|
||||
CHECK_LE( s.QYn, 4 );
|
||||
MBEDTLS_ASSERT( s.Xn <= 4 );
|
||||
MBEDTLS_ASSERT( s.Yn <= 4 );
|
||||
MBEDTLS_ASSERT( s.Zn <= 4 );
|
||||
MBEDTLS_ASSERT( s.QXn <= 4 );
|
||||
MBEDTLS_ASSERT( s.QYn <= 4 );
|
||||
memcpy( s.X, P->X.p, s.Xn * 8 );
|
||||
memcpy( s.Y, P->Y.p, s.Yn * 8 );
|
||||
memcpy( s.Z, P->Z.p, s.Zn * 8 );
|
||||
|
|
24
third_party/mbedtls/ecp384.c
vendored
24
third_party/mbedtls/ecp384.c
vendored
|
@ -16,11 +16,9 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/mbedtls/bignum_internal.h"
|
||||
|
@ -189,8 +187,8 @@ mbedtls_p384_mul( uint64_t X[12],
|
|||
}
|
||||
else
|
||||
{
|
||||
if( A == X ) A = gc( memcpy( malloc( 6 * 8 ), A, 6 * 8 ) );
|
||||
if( B == X ) B = gc( memcpy( malloc( 6 * 8 ), B, 6 * 8 ) );
|
||||
if( A == X ) A = _gc( memcpy( malloc( 6 * 8 ), A, 6 * 8 ) );
|
||||
if( B == X ) B = _gc( memcpy( malloc( 6 * 8 ), B, 6 * 8 ) );
|
||||
Mul( X, A, n, B, m );
|
||||
mbedtls_platform_zeroize( X + n + m, (12 - n - m) * 8 );
|
||||
}
|
||||
|
@ -305,7 +303,7 @@ mbedtls_p384_add( uint64_t X[7],
|
|||
ADC( X[5], A[5], B[5], c, X[6] );
|
||||
#endif
|
||||
mbedtls_p384_rum( X );
|
||||
DCHECK_EQ(0, X[6]);
|
||||
MBEDTLS_ASSERT(0 == X[6]);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -350,7 +348,7 @@ mbedtls_p384_sub( uint64_t X[7],
|
|||
#endif
|
||||
while( (int64_t)X[6] < 0 )
|
||||
mbedtls_p384_gro( X );
|
||||
DCHECK_EQ(0, X[6]);
|
||||
MBEDTLS_ASSERT(0 == X[6]);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -378,7 +376,7 @@ mbedtls_p384_hub( uint64_t A[7],
|
|||
: "rax", "rcx", "memory", "cc");
|
||||
while( (int64_t)A[6] < 0 )
|
||||
mbedtls_p384_gro( A );
|
||||
DCHECK_EQ(0, A[6]);
|
||||
MBEDTLS_ASSERT(0 == A[6]);
|
||||
#else
|
||||
mbedtls_p384_sub(A, A, B);
|
||||
#endif
|
||||
|
@ -460,11 +458,11 @@ int mbedtls_p384_add_mixed( const mbedtls_ecp_group *G,
|
|||
s.Zn = mbedtls_mpi_limbs( &P->Z );
|
||||
s.QXn = mbedtls_mpi_limbs( &Q->X );
|
||||
s.QYn = mbedtls_mpi_limbs( &Q->Y );
|
||||
CHECK_LE( s.Xn, 6 );
|
||||
CHECK_LE( s.Yn, 6 );
|
||||
CHECK_LE( s.Zn, 6 );
|
||||
CHECK_LE( s.QXn, 6 );
|
||||
CHECK_LE( s.QYn, 6 );
|
||||
MBEDTLS_ASSERT( s.Xn <= 6 );
|
||||
MBEDTLS_ASSERT( s.Yn <= 6 );
|
||||
MBEDTLS_ASSERT( s.Zn <= 6 );
|
||||
MBEDTLS_ASSERT( s.QXn <= 6 );
|
||||
MBEDTLS_ASSERT( s.QYn <= 6 );
|
||||
memcpy( s.X, P->X.p, s.Xn * 8 );
|
||||
memcpy( s.Y, P->Y.p, s.Yn * 8 );
|
||||
memcpy( s.Z, P->Z.p, s.Zn * 8 );
|
||||
|
|
2
third_party/mbedtls/karatsuba.c
vendored
2
third_party/mbedtls/karatsuba.c
vendored
|
@ -16,8 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/mbedtls/bignum_internal.h"
|
||||
|
|
2
third_party/mbedtls/platform.h
vendored
2
third_party/mbedtls/platform.h
vendored
|
@ -51,7 +51,7 @@ COSMOPOLITAN_C_START_
|
|||
#define MBEDTLS_ASSERT(EXPR) \
|
||||
((void)((EXPR) || (__assert_fail(#EXPR, __FILE__, __LINE__), 0)))
|
||||
#else
|
||||
#define MBEDTLS_ASSERT(EXPR) (void)0
|
||||
#define MBEDTLS_ASSERT(EXPR) _unassert(EXPR)
|
||||
#endif
|
||||
|
||||
typedef struct mbedtls_platform_context {
|
||||
|
|
11
third_party/mbedtls/test/lib.c
vendored
11
third_party/mbedtls/test/lib.c
vendored
|
@ -14,7 +14,6 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
|
@ -77,14 +76,6 @@ jmp_buf jmp_tmp;
|
|||
int option_verbose = 1;
|
||||
mbedtls_test_info_t mbedtls_test_info;
|
||||
|
||||
static uint64_t Rando(void) {
|
||||
static uint64_t x = 0x18abac12f3191aed;
|
||||
uint64_t z = (x += 0x9e3779b97f4a7c15);
|
||||
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
|
||||
z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
|
||||
return z ^ (z >> 31);
|
||||
}
|
||||
|
||||
int mbedtls_test_platform_setup(void) {
|
||||
char *p;
|
||||
int ret = 0;
|
||||
|
@ -128,7 +119,7 @@ int mbedtls_hardware_poll(void *wut, unsigned char *p, size_t n, size_t *olen) {
|
|||
size_t i, j;
|
||||
unsigned char b[8];
|
||||
for (i = 0; i < n; ++i) {
|
||||
x = Rando();
|
||||
x = lemur64();
|
||||
WRITE64LE(b, x);
|
||||
for (j = 0; j < 8 && i + j < n; ++j) {
|
||||
p[i + j] = b[j];
|
||||
|
|
45
third_party/regex/regcomp.c
vendored
45
third_party/regex/regcomp.c
vendored
|
@ -334,7 +334,7 @@ static reg_errcode_t tre_stack_push(tre_stack_t *s,
|
|||
if (new_buffer == NULL) {
|
||||
return REG_ESPACE;
|
||||
}
|
||||
assert(new_size > s->size);
|
||||
_unassert(new_size > s->size);
|
||||
s->size = new_size;
|
||||
s->stack = new_buffer;
|
||||
tre_stack_push(s, value);
|
||||
|
@ -1209,7 +1209,7 @@ static reg_errcode_t tre_add_tags(tre_mem_t mem, tre_stack_t *stack,
|
|||
status = REG_ESPACE;
|
||||
break;
|
||||
}
|
||||
assert(tnfa->submatch_data[id].parents == NULL);
|
||||
_unassert(tnfa->submatch_data[id].parents == NULL);
|
||||
tnfa->submatch_data[id].parents = p;
|
||||
for (i = 0; parents[i] >= 0; i++) p[i] = parents[i];
|
||||
p[i] = -1;
|
||||
|
@ -1254,7 +1254,7 @@ static reg_errcode_t tre_add_tags(tre_mem_t mem, tre_stack_t *stack,
|
|||
next_tag++;
|
||||
}
|
||||
} else {
|
||||
assert(!IS_TAG(lit));
|
||||
_unassert(!IS_TAG(lit));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1498,8 +1498,7 @@ static reg_errcode_t tre_add_tags(tre_mem_t mem, tre_stack_t *stack,
|
|||
}
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
unreachable;
|
||||
|
||||
} /* end switch(symbol) */
|
||||
} /* end while(tre_stack_num_objects(stack) > bottom) */
|
||||
|
@ -1517,7 +1516,7 @@ static reg_errcode_t tre_add_tags(tre_mem_t mem, tre_stack_t *stack,
|
|||
num_minimals++;
|
||||
}
|
||||
|
||||
assert(tree->num_tags == num_tags);
|
||||
_unassert(tree->num_tags == num_tags);
|
||||
tnfa->end_tag = num_tags;
|
||||
tnfa->num_tags = num_tags;
|
||||
tnfa->num_minimals = num_minimals;
|
||||
|
@ -1650,8 +1649,7 @@ static reg_errcode_t tre_copy_ast(tre_mem_t mem, tre_stack_t *stack,
|
|||
break;
|
||||
}
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
unreachable;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1726,8 +1724,7 @@ static reg_errcode_t tre_expand_ast(tre_mem_t mem, tre_stack_t *stack,
|
|||
break;
|
||||
}
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
unreachable;
|
||||
}
|
||||
break;
|
||||
case EXPAND_AFTER_ITER: {
|
||||
|
@ -1801,8 +1798,7 @@ static reg_errcode_t tre_expand_ast(tre_mem_t mem, tre_stack_t *stack,
|
|||
break;
|
||||
}
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1958,14 +1954,13 @@ static reg_errcode_t tre_match_empty(tre_stack_t *stack, tre_ast_node_t *node,
|
|||
}
|
||||
break;
|
||||
case ASSERTION:
|
||||
assert(lit->code_max >= 1 || lit->code_max <= ASSERT_LAST);
|
||||
_unassert(lit->code_max >= 1 || lit->code_max <= ASSERT_LAST);
|
||||
if (assertions != NULL) *assertions |= lit->code_max;
|
||||
break;
|
||||
case EMPTY:
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
unreachable;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1979,14 +1974,14 @@ static reg_errcode_t tre_match_empty(tre_stack_t *stack, tre_ast_node_t *node,
|
|||
else if (uni->right->nullable)
|
||||
STACK_PUSHX(stack, voidptr, uni->right)
|
||||
else
|
||||
assert(0);
|
||||
unreachable;
|
||||
break;
|
||||
|
||||
case CATENATION:
|
||||
/* The path must go through both children. */
|
||||
cat = (tre_catenation_t *)node->obj;
|
||||
assert(cat->left->nullable);
|
||||
assert(cat->right->nullable);
|
||||
_unassert(cat->left->nullable);
|
||||
_unassert(cat->right->nullable);
|
||||
STACK_PUSHX(stack, voidptr, cat->left);
|
||||
STACK_PUSHX(stack, voidptr, cat->right);
|
||||
break;
|
||||
|
@ -1999,8 +1994,7 @@ static reg_errcode_t tre_match_empty(tre_stack_t *stack, tre_ast_node_t *node,
|
|||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2188,8 +2182,7 @@ static reg_errcode_t tre_compute_nfl(tre_mem_t mem, tre_stack_t *stack,
|
|||
}
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2252,8 +2245,8 @@ static reg_errcode_t tre_make_trans(tre_pos_and_tags_t *p1,
|
|||
(p1->class ? ASSERT_CHAR_CLASS : 0) |
|
||||
(p1->neg_classes != NULL ? ASSERT_CHAR_CLASS_NEG : 0);
|
||||
if (p1->backref >= 0) {
|
||||
assert((trans->assertions & ASSERT_CHAR_CLASS) == 0);
|
||||
assert(p2->backref < 0);
|
||||
_unassert((trans->assertions & ASSERT_CHAR_CLASS) == 0);
|
||||
_unassert(p2->backref < 0);
|
||||
trans->u.backref = p1->backref;
|
||||
trans->assertions |= ASSERT_BACKREF;
|
||||
} else
|
||||
|
@ -2363,10 +2356,10 @@ static reg_errcode_t tre_ast_to_tnfa(tre_ast_node_t *node,
|
|||
|
||||
case ITERATION:
|
||||
iter = (tre_iteration_t *)node->obj;
|
||||
assert(iter->max == -1 || iter->max == 1);
|
||||
_unassert(iter->max == -1 || iter->max == 1);
|
||||
|
||||
if (iter->max == -1) {
|
||||
assert(iter->min == 0 || iter->min == 1);
|
||||
_unassert(iter->min == 0 || iter->min == 1);
|
||||
/* Add a transition from each last position in the iterated
|
||||
expression to each first position. */
|
||||
errcode = tre_make_trans(iter->arg->lastpos, iter->arg->firstpos,
|
||||
|
|
9
third_party/regex/regexec.c
vendored
9
third_party/regex/regexec.c
vendored
|
@ -56,6 +56,7 @@
|
|||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/limits.h"
|
||||
#include "third_party/regex/tre.inc"
|
||||
|
||||
|
@ -393,7 +394,7 @@ static reg_errcode_t tre_tnfa_run_parallel(const tre_tnfa_t *tnfa,
|
|||
reach_next_i++;
|
||||
|
||||
} else {
|
||||
assert(reach_pos[trans_i->state_id].pos == pos);
|
||||
_unassert(reach_pos[trans_i->state_id].pos == pos);
|
||||
/* Another path has also reached this state. We choose
|
||||
the winner by examining the tag values for both
|
||||
paths. */
|
||||
|
@ -520,7 +521,7 @@ typedef struct tre_backtrack_struct {
|
|||
#define BT_STACK_POP() \
|
||||
do { \
|
||||
int i; \
|
||||
assert(stack->prev); \
|
||||
_unassert(stack->prev); \
|
||||
pos = stack->item.pos; \
|
||||
str_byte = stack->item.str_byte; \
|
||||
state = stack->item.state; \
|
||||
|
@ -846,8 +847,8 @@ static void tre_fill_pmatch(size_t nmatch, regmatch_t pmatch[], int cflags,
|
|||
submatches. */
|
||||
i = 0;
|
||||
while (i < tnfa->num_submatches && i < nmatch) {
|
||||
if (pmatch[i].rm_eo == -1) assert(pmatch[i].rm_so == -1);
|
||||
assert(pmatch[i].rm_so <= pmatch[i].rm_eo);
|
||||
if (pmatch[i].rm_eo == -1) _unassert(pmatch[i].rm_so == -1);
|
||||
_unassert(pmatch[i].rm_so <= pmatch[i].rm_eo);
|
||||
|
||||
parents = submatch_data[i].parents;
|
||||
if (parents != NULL)
|
||||
|
|
1
third_party/zlib/deflate.c
vendored
1
third_party/zlib/deflate.c
vendored
|
@ -5,7 +5,6 @@
|
|||
* Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
#include "libc/assert.h"
|
||||
#include "third_party/zlib/deflate.internal.h"
|
||||
#include "third_party/zlib/insert_string.internal.h"
|
||||
#include "third_party/zlib/internal.h"
|
||||
|
|
13
third_party/zlib/zutil.c
vendored
13
third_party/zlib/zutil.c
vendored
|
@ -5,7 +5,6 @@
|
|||
* Copyright (C) 1995-2017 Jean-loup Gailly
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
@ -319,8 +318,11 @@ voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
|
|||
unsigned size;
|
||||
{
|
||||
(void)opaque;
|
||||
_npassert(_weaken(malloc));
|
||||
return _weaken(malloc)(items * size);
|
||||
if (_weaken(malloc)) {
|
||||
return _weaken(malloc)(items * size);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ZLIB_INTERNAL zcfree (opaque, ptr)
|
||||
|
@ -328,8 +330,9 @@ void ZLIB_INTERNAL zcfree (opaque, ptr)
|
|||
voidpf ptr;
|
||||
{
|
||||
(void)opaque;
|
||||
_npassert(_weaken(free));
|
||||
_weaken(free)(ptr);
|
||||
if (_weaken(free)) {
|
||||
_weaken(free)(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MY_ZCALLOC */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue