mirror of
https://git.code.sf.net/p/zint/code
synced 2025-12-23 21:07:05 +00:00
general: prefix all INTERNAL funcs/tables with zint_, except
those in "backend/common.h", which are prefixed by `z_` - makes symbol clashes more unlikely when zint is statically linked (ticket #337, props Ulrich Becker) DOTCODE: fix padding allowance (10 -> 52 - probable max 35) to cover cases with large no. of columns requested and little data, to prevent `codeword_array` buffer overflow AZTEC/CODEONE: some code fiddling general_field: prefix defines with `GF_`, shorten static funcs prefix `general_field_` -> `gf_`
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/* large.c - Handles binary manipulation of large numbers */
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2008-2023 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2008-2025 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -30,7 +30,7 @@
|
||||
*/
|
||||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
|
||||
/* `large_mul_u64()` and `large_div_u64()` are adapted from articles by F. W. Jacob
|
||||
/* `zint_large_mul_u64()` and `zint_large_div_u64()` are adapted from articles by F. W. Jacob
|
||||
* https://www.codeproject.com/Tips/618570/UInt-Multiplication-Squaring
|
||||
* "This article, along with any associated source code and files, is licensed under The BSD License"
|
||||
* http://www.codeproject.com/Tips/785014/UInt-Division-Modulus
|
||||
@@ -40,7 +40,7 @@
|
||||
* "You are free to use, copy, and distribute any of the code on this web site, whether modified by you or not."
|
||||
* https://web.archive.org/web/20190716204559/http://www.hackersdelight.org/permissions.htm
|
||||
*
|
||||
* `clz_u64()` and other bits and pieces are adapted from r128.h by Alan Hickman (fahickman)
|
||||
* `zint_clz_u64()` and other bits and pieces are adapted from r128.h by Alan Hickman (fahickman)
|
||||
* https://github.com/fahickman/r128/blob/master/r128.h
|
||||
* "R128 is released into the public domain. See LICENSE for details." LICENSE is The Unlicense.
|
||||
*/
|
||||
@@ -52,7 +52,7 @@
|
||||
#define MASK32 0xFFFFFFFF
|
||||
|
||||
/* Convert decimal string `s` of (at most) length `length` to 64-bit and place in 128-bit `t` */
|
||||
INTERNAL void large_load_str_u64(large_uint *t, const unsigned char *s, const int length) {
|
||||
INTERNAL void zint_large_load_str_u64(large_uint *t, const unsigned char *s, const int length) {
|
||||
uint64_t val = 0;
|
||||
const unsigned char *const se = s + length;
|
||||
for (; s < se && z_isdigit(*s); s++) {
|
||||
@@ -64,13 +64,13 @@ INTERNAL void large_load_str_u64(large_uint *t, const unsigned char *s, const in
|
||||
}
|
||||
|
||||
/* Add 128-bit `s` to 128-bit `t` */
|
||||
INTERNAL void large_add(large_uint *t, const large_uint *s) {
|
||||
INTERNAL void zint_large_add(large_uint *t, const large_uint *s) {
|
||||
t->lo += s->lo;
|
||||
t->hi += s->hi + (t->lo < s->lo);
|
||||
}
|
||||
|
||||
/* Add 64-bit `s` to 128-bit `t` */
|
||||
INTERNAL void large_add_u64(large_uint *t, const uint64_t s) {
|
||||
INTERNAL void zint_large_add_u64(large_uint *t, const uint64_t s) {
|
||||
t->lo += s;
|
||||
if (t->lo < s) {
|
||||
t->hi++;
|
||||
@@ -78,7 +78,7 @@ INTERNAL void large_add_u64(large_uint *t, const uint64_t s) {
|
||||
}
|
||||
|
||||
/* Subtract 64-bit `s` from 128-bit `t` */
|
||||
INTERNAL void large_sub_u64(large_uint *t, const uint64_t s) {
|
||||
INTERNAL void zint_large_sub_u64(large_uint *t, const uint64_t s) {
|
||||
uint64_t r = t->lo - s;
|
||||
if (r > t->lo) {
|
||||
t->hi--;
|
||||
@@ -107,7 +107,7 @@ INTERNAL void large_sub_u64(large_uint *t, const uint64_t s) {
|
||||
* p10
|
||||
* p11 + k10
|
||||
*/
|
||||
INTERNAL void large_mul_u64(large_uint *t, const uint64_t s) {
|
||||
INTERNAL void zint_large_mul_u64(large_uint *t, const uint64_t s) {
|
||||
uint64_t thi = t->hi;
|
||||
uint64_t tlo0 = t->lo & MASK32;
|
||||
uint64_t tlo1 = t->lo >> 32;
|
||||
@@ -141,7 +141,7 @@ static int clz_u64(uint64_t x) {
|
||||
}
|
||||
|
||||
#ifdef ZINT_TEST /* Wrapper for direct testing */
|
||||
INTERNAL int clz_u64_test(uint64_t x) {
|
||||
INTERNAL int zint_test_clz_u64(uint64_t x) {
|
||||
return clz_u64(x);
|
||||
}
|
||||
#endif
|
||||
@@ -149,7 +149,7 @@ INTERNAL int clz_u64_test(uint64_t x) {
|
||||
/* Divide 128-bit dividend `t` by 64-bit divisor `v`, returning 64-bit remainder
|
||||
* See Jacob `divmod128by128/64()` and Warren Section 9–2 (divmu64.c.txt)
|
||||
* Note digits are 32-bit parts */
|
||||
INTERNAL uint64_t large_div_u64(large_uint *t, uint64_t v) {
|
||||
INTERNAL uint64_t zint_large_div_u64(large_uint *t, uint64_t v) {
|
||||
const uint64_t b = 0x100000000; /* Number base (2**32) */
|
||||
uint64_t qhi = 0; /* High digit of returned quotient */
|
||||
|
||||
@@ -241,7 +241,7 @@ INTERNAL uint64_t large_div_u64(large_uint *t, uint64_t v) {
|
||||
}
|
||||
|
||||
/* Unset a bit (zero-based) */
|
||||
INTERNAL void large_unset_bit(large_uint *t, const int bit) {
|
||||
INTERNAL void zint_large_unset_bit(large_uint *t, const int bit) {
|
||||
if (bit < 64) {
|
||||
t->lo &= ~(((uint64_t) 1) << bit);
|
||||
} else if (bit < 128) {
|
||||
@@ -250,7 +250,7 @@ INTERNAL void large_unset_bit(large_uint *t, const int bit) {
|
||||
}
|
||||
|
||||
/* Output large_uint into an unsigned int array of size `size`, each element containing `bits` bits */
|
||||
INTERNAL void large_uint_array(const large_uint *t, unsigned int *uint_array, const int size, int bits) {
|
||||
INTERNAL void zint_large_uint_array(const large_uint *t, unsigned int *uint_array, const int size, int bits) {
|
||||
int i, j;
|
||||
uint64_t mask;
|
||||
if (bits <= 0) {
|
||||
@@ -280,12 +280,12 @@ INTERNAL void large_uint_array(const large_uint *t, unsigned int *uint_array, co
|
||||
}
|
||||
}
|
||||
|
||||
/* As `large_uint_array()` above, except output to unsigned char array */
|
||||
INTERNAL void large_uchar_array(const large_uint *t, unsigned char *uchar_array, const int size, int bits) {
|
||||
/* As `zint_large_uint_array()` above, except output to unsigned char array */
|
||||
INTERNAL void zint_large_uchar_array(const large_uint *t, unsigned char *uchar_array, const int size, int bits) {
|
||||
int i;
|
||||
unsigned int *uint_array = (unsigned int *) z_alloca(sizeof(unsigned int) * (size ? size : 1));
|
||||
|
||||
large_uint_array(t, uint_array, size, bits);
|
||||
zint_large_uint_array(t, uint_array, size, bits);
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
uchar_array[i] = (unsigned char) uint_array[i];
|
||||
@@ -293,11 +293,11 @@ INTERNAL void large_uchar_array(const large_uint *t, unsigned char *uchar_array,
|
||||
}
|
||||
|
||||
/* Format large_uint into buffer, which should be at least 35 chars in size */
|
||||
INTERNAL char *large_dump(const large_uint *t, char *buf) {
|
||||
unsigned int tlo1 = (unsigned int) (large_lo(t) >> 32);
|
||||
unsigned int tlo0 = (unsigned int) (large_lo(t) & MASK32);
|
||||
unsigned int thi1 = (unsigned int) (large_hi(t) >> 32);
|
||||
unsigned int thi0 = (unsigned int) (large_hi(t) & MASK32);
|
||||
INTERNAL char *zint_large_dump(const large_uint *t, char *buf) {
|
||||
unsigned int tlo1 = (unsigned int) (zint_large_lo(t) >> 32);
|
||||
unsigned int tlo0 = (unsigned int) (zint_large_lo(t) & MASK32);
|
||||
unsigned int thi1 = (unsigned int) (zint_large_hi(t) >> 32);
|
||||
unsigned int thi0 = (unsigned int) (zint_large_hi(t) & MASK32);
|
||||
|
||||
if (thi1) {
|
||||
sprintf(buf, "0x%X%08X%08X%08X", thi1, thi0, tlo1, tlo0);
|
||||
@@ -312,10 +312,10 @@ INTERNAL char *large_dump(const large_uint *t, char *buf) {
|
||||
}
|
||||
|
||||
/* Output formatted large_uint to stdout */
|
||||
INTERNAL void large_print(const large_uint *t) {
|
||||
INTERNAL void zint_large_print(const large_uint *t) {
|
||||
char buf[35]; /* 2 (0x) + 32 (hex) + 1 */
|
||||
|
||||
puts(large_dump(t, buf));
|
||||
puts(zint_large_dump(t, buf));
|
||||
}
|
||||
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
||||
Reference in New Issue
Block a user