help the compiler create more efficient code

Patch from Michael <virtual_worlds@gmx.de>
Full text: As usual I have modified only minor things to remove warnigs when compiled as C++ code, have added some const-specifiers where possible to help the compiler create more efficient code and added some static-specifiers to make functions invisible to other modules.
This commit is contained in:
Robin Stuart 2017-05-29 10:43:47 +01:00
parent d08237d06e
commit b3a1b24d18
29 changed files with 275 additions and 298 deletions

View File

@ -69,7 +69,7 @@ static inline char convert_pattern(char data, int shift) {
/* Adds Reed-Solomon error correction to auspost */ /* Adds Reed-Solomon error correction to auspost */
void rs_error(char data_pattern[]) { void rs_error(char data_pattern[]) {
int reader, triple_writer = 0; size_t reader, triple_writer = 0;
char triple[31], inv_triple[31]; char triple[31], inv_triple[31];
unsigned char result[5]; unsigned char result[5];

View File

@ -68,7 +68,7 @@ static void insert(char binary_string[], const size_t posn, const char newbit) {
/** /**
* Encode input data into a binary string * Encode input data into a binary string
*/ */
static int aztec_text_process(const unsigned char source[], const unsigned int src_len, char binary_string[], const int gs1, const int eci, int debug) { static int aztec_text_process(const unsigned char source[], const size_t src_len, char binary_string[], const int gs1, const int eci, const int debug) {
int i, j, k, bytes; int i, j, k, bytes;
int curtable, newtable, lasttable, chartype, maplength, blocks; int curtable, newtable, lasttable, chartype, maplength, blocks;
#ifndef _MSC_VER #ifndef _MSC_VER
@ -812,7 +812,7 @@ static void populate_map() {
AztecMap[(avoidReferenceGrid(77) * 151) + avoidReferenceGrid(76)] = 1; AztecMap[(avoidReferenceGrid(77) * 151) + avoidReferenceGrid(76)] = 1;
} }
int aztec(struct zint_symbol *symbol, unsigned char source[], int length) { int aztec(struct zint_symbol *symbol, unsigned char source[], const size_t length) {
int x, y, i, j, p, data_blocks, ecc_blocks, layers, total_bits; int x, y, i, j, p, data_blocks, ecc_blocks, layers, total_bits;
char binary_string[20000], bit_pattern[20045], descriptor[42]; char binary_string[20000], bit_pattern[20045], descriptor[42];
char adjusted_string[20000]; char adjusted_string[20000];

View File

@ -629,7 +629,7 @@ void SumASCII(uchar **ppOutPos, int Sum, int CharacterSet)
/* Main function called by zint framework /* Main function called by zint framework
*/ */
int codablock(struct zint_symbol *symbol, unsigned char source[], int length) { int codablock(struct zint_symbol *symbol,const unsigned char source[], const size_t length) {
int charCur; int charCur;
int dataLength; int dataLength;
int Error; int Error;

View File

@ -291,9 +291,10 @@ void c128_set_c(unsigned char source_a, unsigned char source_b, char dest[], int
} }
/* Handle Code 128 and NVE-18 */ /* Handle Code 128 and NVE-18 */
int code_128(struct zint_symbol *symbol, unsigned char source[], int length) { int code_128(struct zint_symbol *symbol, unsigned char source[], const size_t length) {
int i, j, k, values[170] = {0}, bar_characters, read, total_sum; int i, j, k, values[170] = {0}, bar_characters, read, total_sum;
int error_number, indexchaine, indexliste, sourcelen, f_state; int error_number, indexchaine, indexliste, f_state;
size_t sourcelen;
char set[170] = {' '}, fset[170] = {' '}, mode, last_set, current_set = ' '; char set[170] = {' '}, fset[170] = {' '}, mode, last_set, current_set = ' ';
float glyph_count; float glyph_count;
char dest[1000]; char dest[1000];

View File

@ -52,6 +52,8 @@
#define CANDB 98 #define CANDB 98
#define CANDBB 99 #define CANDBB 99
extern int parunmodd(const unsigned char llyth);
static int list[2][170]; static int list[2][170];
static const char *C16KTable[107] = { static const char *C16KTable[107] = {
@ -86,20 +88,20 @@ static const int C16KStopValues[16] = {
0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3 0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3
}; };
void grwp16(int *indexliste) { static void grwp16(unsigned int *indexliste) {
int i, j; int i, j;
/* bring together same type blocks */ /* bring together same type blocks */
if (*(indexliste) > 1) { if (*(indexliste) > 1) {
i = 1; i = 1;
while (i < *(indexliste)) { while(i < (int)*(indexliste)) {
if (list[1][i - 1] == list[1][i]) { if (list[1][i - 1] == list[1][i]) {
/* bring together */ /* bring together */
list[0][i - 1] = list[0][i - 1] + list[0][i]; list[0][i - 1] = list[0][i - 1] + list[0][i];
j = i + 1; j = i + 1;
/* decreace the list */ /* decreace the list */
while (j < *(indexliste)) { while(j < (int)*(indexliste)) {
list[0][j - 1] = list[0][j]; list[0][j - 1] = list[0][j];
list[1][j - 1] = list[1][j]; list[1][j - 1] = list[1][j];
j++; j++;
@ -113,10 +115,10 @@ void grwp16(int *indexliste) {
} }
/* Implements rules from ISO 15417 Annex E */ /* Implements rules from ISO 15417 Annex E */
void dxsmooth16(int *indexliste) { static void dxsmooth16(unsigned int *indexliste) {
int i, current, last, next, length; int i, current, last, next, length;
for (i = 0; i < *(indexliste); i++) { for(i = 0; i < (int)*(indexliste); i++) {
current = list[1][i]; current = list[1][i];
length = list[0][i]; length = list[0][i];
if (i != 0) { if (i != 0) {
@ -220,7 +222,7 @@ void dxsmooth16(int *indexliste) {
} }
void c16k_set_a(unsigned char source, unsigned int values[], unsigned int *bar_chars) { static void c16k_set_a(const unsigned char source, unsigned int values[], unsigned int *bar_chars) {
if (source > 127) { if (source > 127) {
if (source < 160) { if (source < 160) {
values[(*bar_chars)] = source + 64 - 128; values[(*bar_chars)] = source + 64 - 128;
@ -237,7 +239,7 @@ void c16k_set_a(unsigned char source, unsigned int values[], unsigned int *bar_c
(*bar_chars)++; (*bar_chars)++;
} }
void c16k_set_b(unsigned char source, unsigned int values[], unsigned int *bar_chars) { static void c16k_set_b(const unsigned char source, unsigned int values[], unsigned int *bar_chars) {
if (source > 127) { if (source > 127) {
values[(*bar_chars)] = source - 32 - 128; values[(*bar_chars)] = source - 32 - 128;
} else { } else {
@ -246,7 +248,7 @@ void c16k_set_b(unsigned char source, unsigned int values[], unsigned int *bar_c
(*bar_chars)++; (*bar_chars)++;
} }
void c16k_set_c(unsigned char source_a, unsigned char source_b, unsigned int values[], unsigned int *bar_chars) { static void c16k_set_c(const unsigned char source_a, unsigned char source_b, unsigned int values[], unsigned int *bar_chars) {
int weight; int weight;
weight = (10 * ctoi(source_a)) + ctoi(source_b); weight = (10 * ctoi(source_a)) + ctoi(source_b);
@ -254,17 +256,17 @@ void c16k_set_c(unsigned char source_a, unsigned char source_b, unsigned int val
(*bar_chars)++; (*bar_chars)++;
} }
int code16k(struct zint_symbol *symbol, unsigned char source[], int length) { int code16k(struct zint_symbol *symbol, unsigned char source[], const size_t length) {
char width_pattern[100]; char width_pattern[100];
int current_row, rows_needed, flip_flop, looper, first_check, second_check; int current_row, rows_needed, flip_flop, looper, first_check, second_check;
int indexliste, indexchaine, pads_needed, f_state; int indexchaine, f_state;
char set[160] = {' '}, fset[160] = {' '}, mode, last_set, current_set; char set[160] = {' '}, fset[160] = {' '}, mode, last_set, current_set;
unsigned int i, j, k, m, read, mx_reader, writer; unsigned int pads_needed, indexliste, i, j, k, m, read, mx_reader, writer;
unsigned int values[160] = {0}; unsigned int values[160] = {0};
unsigned int bar_characters; unsigned int bar_characters;
float glyph_count; float glyph_count;
int errornum, first_sum, second_sum; int errornum, first_sum, second_sum;
int input_length; size_t input_length;
int gs1, c_count; int gs1, c_count;
errornum = 0; errornum = 0;
@ -483,7 +485,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Calculate how tall the symbol will be */ /* Calculate how tall the symbol will be */
glyph_count = glyph_count + 2.0; glyph_count = glyph_count + 2.0;
i = glyph_count; i = (int)glyph_count;
rows_needed = (i / 5); rows_needed = (i / 5);
if (i % 5 > 0) { if (i % 5 > 0) {
rows_needed++; rows_needed++;

View File

@ -106,18 +106,6 @@ int is_sane(const char test_string[], const unsigned char source[], const size_t
return 0; return 0;
} }
/* Returns the position of data in set_string */
int posn(const char set_string[], const char data) {
size_t i, n = strlen(set_string);
for (i = 0; i < n; i++) {
if (data == set_string[i]) {
return i;
}
}
return 0;
}
/* Replaces huge switch statements for looking up in tables */ /* Replaces huge switch statements for looking up in tables */
void lookup(const char set_string[], const char *table[], const char data, char dest[]) { void lookup(const char set_string[], const char *table[], const char data, char dest[]) {
size_t i, n = strlen(set_string); size_t i, n = strlen(set_string);
@ -129,6 +117,18 @@ void lookup(const char set_string[], const char *table[], const char data, char
} }
} }
/* Returns the position of data in set_string */
int posn(const char set_string[], const char data) {
int i, n = (int)strlen(set_string);
for (i = 0; i < n; i++) {
if (data == set_string[i]) {
return i;
}
}
return 0;
}
/* Return true (1) if a module is dark/black, otherwise false (0) */ /* Return true (1) if a module is dark/black, otherwise false (0) */
int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord) { int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord) {
return (symbol->encoded_data[y_coord][x_coord / 7] >> (x_coord % 7)) & 1; return (symbol->encoded_data[y_coord][x_coord / 7] >> (x_coord % 7)) & 1;
@ -180,10 +180,8 @@ void expand(struct zint_symbol *symbol, const char data[]) {
/* Indicates which symbologies can have row binding */ /* Indicates which symbologies can have row binding */
int is_stackable(const int symbology) { int is_stackable(const int symbology) {
int retval = 0;
if (symbology < BARCODE_PDF417) { if (symbology < BARCODE_PDF417) {
retval = 1; return 1;
} }
switch (symbology) { switch (symbology) {
@ -197,10 +195,10 @@ int is_stackable(const int symbology) {
case BARCODE_ITF14: case BARCODE_ITF14:
case BARCODE_CODE32: case BARCODE_CODE32:
case BARCODE_CODABLOCKF: case BARCODE_CODABLOCKF:
retval = 1; return 1;
} }
return retval; return 0;
} }
/* Indicates which symbols can have addon (EAN-2 and EAN-5) */ /* Indicates which symbols can have addon (EAN-2 and EAN-5) */
@ -240,8 +238,9 @@ int istwodigits(const unsigned char source[], const int position) {
return 0; return 0;
} }
int utf8toutf16(struct zint_symbol *symbol, const unsigned char source[], int vals[], int *length) { int utf8toutf16(struct zint_symbol *symbol, const unsigned char source[], int vals[], size_t *length) {
int bpos, jpos, error_number; size_t bpos;
int jpos, error_number;
int next; int next;
bpos = 0; bpos = 0;
@ -291,7 +290,8 @@ int utf8toutf16(struct zint_symbol *symbol, const unsigned char source[], int va
return error_number; return error_number;
} }
void set_minimum_height(struct zint_symbol *symbol, int min_height) {
void set_minimum_height(struct zint_symbol *symbol, const int min_height) {
/* Enforce minimum permissable height of rows */ /* Enforce minimum permissable height of rows */
int fixed_height = 0; int fixed_height = 0;
int zero_count = 0; int zero_count = 0;

View File

@ -62,18 +62,16 @@ extern "C" {
extern int is_sane(const char test_string[], const unsigned char source[], const size_t length); extern int is_sane(const char test_string[], const unsigned char source[], const size_t length);
extern void lookup(const char set_string[], const char *table[], const char data, char dest[]); extern void lookup(const char set_string[], const char *table[], const char data, char dest[]);
extern int posn(const char set_string[], const char data); extern int posn(const char set_string[], const char data);
extern void expand(struct zint_symbol *symbol, const char data[]);
extern int is_stackable(const int symbology);
extern int is_extendable(const int symbology);
extern int roundup(const float input);
extern int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord); extern int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord);
extern void set_module(struct zint_symbol *symbol, const int y_coord, const int x_coord); extern void set_module(struct zint_symbol *symbol, const int y_coord, const int x_coord);
extern void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord);
extern int istwodigits(const unsigned char source[], const int position); extern int istwodigits(const unsigned char source[], const int position);
extern double froundup(const double input);
extern int parunmodd(const unsigned char llyth); extern int parunmodd(const unsigned char llyth);
extern int utf8toutf16(struct zint_symbol *symbol, const unsigned char source[], int vals[], int *length); extern void expand(struct zint_symbol *symbol, const char data[]);
extern void set_minimum_height(struct zint_symbol *symbol, int min_height); extern void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord);
extern int is_stackable(const int symbology);
extern int is_extendable(const int symbology);
extern int utf8toutf16(struct zint_symbol *symbol, const unsigned char source[], int vals[], size_t *length);
extern void set_minimum_height(struct zint_symbol *symbol, const int min_height);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -72,7 +72,7 @@ extern int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int l
static UINT pwr928[69][7]; static UINT pwr928[69][7];
int _min(int first, int second) { static int _min(int first, int second) {
if (first <= second) if (first <= second)
return first; return first;
@ -81,12 +81,12 @@ int _min(int first, int second) {
} }
/* gets bit in bitString at bitPos */ /* gets bit in bitString at bitPos */
int getBit(UINT *bitStr, int bitPos) { static int getBit(UINT *bitStr, int bitPos) {
return !!(bitStr[bitPos >> 4] & (0x8000 >> (bitPos & 15))); return !!(bitStr[bitPos >> 4] & (0x8000 >> (bitPos & 15)));
} }
/* initialize pwr928 encoding table */ /* initialize pwr928 encoding table */
void init928(void) { static void init928(void) {
int i, j, v; int i, j, v;
int cw[7]; int cw[7];
cw[6] = 1L; cw[6] = 1L;
@ -106,7 +106,7 @@ void init928(void) {
} }
/* converts bit string to base 928 values, codeWords[0] is highest order */ /* converts bit string to base 928 values, codeWords[0] is highest order */
int encode928(UINT bitString[], UINT codeWords[], int bitLng) { static int encode928(UINT bitString[], UINT codeWords[], int bitLng) {
int i, j, b, bitCnt, cwNdx, cwCnt, cwLng; int i, j, b, bitCnt, cwNdx, cwCnt, cwLng;
for (cwNdx = cwLng = b = 0; b < bitLng; b += 69, cwNdx += 7) { for (cwNdx = cwLng = b = 0; b < bitLng; b += 69, cwNdx += 7) {
bitCnt = _min(bitLng - b, 69); bitCnt = _min(bitLng - b, 69);
@ -129,7 +129,7 @@ int encode928(UINT bitString[], UINT codeWords[], int bitLng) {
} }
/* CC-A 2D component */ /* CC-A 2D component */
int cc_a(struct zint_symbol *symbol, char source[], int cc_width) { static int cc_a(struct zint_symbol *symbol, char source[], int cc_width) {
int i, strpos, segment, bitlen, cwCnt, variant, rows; int i, strpos, segment, bitlen, cwCnt, variant, rows;
int k, offset, j, total, rsCodeWords[8]; int k, offset, j, total, rsCodeWords[8];
int LeftRAPStart, RightRAPStart, CentreRAPStart, StartCluster; int LeftRAPStart, RightRAPStart, CentreRAPStart, StartCluster;
@ -363,7 +363,7 @@ int cc_a(struct zint_symbol *symbol, char source[], int cc_width) {
} }
/* CC-B 2D component */ /* CC-B 2D component */
int cc_b(struct zint_symbol *symbol, char source[], int cc_width) { static int cc_b(struct zint_symbol *symbol, char source[], int cc_width) {
int length, i, binloc; int length, i, binloc;
#ifndef _MSC_VER #ifndef _MSC_VER
unsigned char data_string[(strlen(source) / 8) + 3]; unsigned char data_string[(strlen(source) / 8) + 3];
@ -646,7 +646,7 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) {
} }
/* CC-C 2D component - byte compressed PDF417 */ /* CC-C 2D component - byte compressed PDF417 */
int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level) { static int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level) {
int length, i, p, binloc; int length, i, p, binloc;
#ifndef _MSC_VER #ifndef _MSC_VER
unsigned char data_string[(strlen(source) / 8) + 4]; unsigned char data_string[(strlen(source) / 8) + 4];
@ -789,12 +789,12 @@ int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level)
symbol->row_height[i] = 3; symbol->row_height[i] = 3;
} }
symbol->rows = (mclength / cc_width); symbol->rows = (mclength / cc_width);
symbol->width = strlen(pattern); symbol->width = (int)strlen(pattern);
return 0; return 0;
} }
int calc_padding_cca(int binary_length, int cc_width) { static int calc_padding_cca(int binary_length, int cc_width) {
int target_bitsize = 0; int target_bitsize = 0;
switch (cc_width) { switch (cc_width) {
@ -1026,7 +1026,7 @@ int calc_padding_ccc(int binary_length, int *cc_width, int lin_width, int *ecc)
return target_bitsize; return target_bitsize;
} }
int cc_binary_string(struct zint_symbol *symbol, const char source[], char binary_string[], int cc_mode, int *cc_width, int *ecc, int lin_width) { /* Handles all data encodation from section 5 of ISO/IEC 24723 */ static int cc_binary_string(struct zint_symbol *symbol, const char source[], char binary_string[], int cc_mode, int *cc_width, int *ecc, int lin_width) { /* Handles all data encodation from section 5 of ISO/IEC 24723 */
int encoding_method, read_posn, d1, d2, value, alpha_pad; int encoding_method, read_posn, d1, d2, value, alpha_pad;
int i, j, mask, ai_crop, fnc1_latch; int i, j, mask, ai_crop, fnc1_latch;
long int group_val; long int group_val;
@ -1223,7 +1223,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
} }
} }
next_ai_posn = 2 + strlen(ninety); next_ai_posn = 2 + (int)strlen(ninety);
if (source[next_ai_posn] == '[') { if (source[next_ai_posn] == '[') {
/* There are more AIs afterwords */ /* There are more AIs afterwords */
@ -1721,7 +1721,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
} }
} while (i + latch < (int) strlen(general_field)); } while (i + latch < (int) strlen(general_field));
binary_length = strlen(binary_string); binary_length = (int)strlen(binary_string);
switch (cc_mode) { switch (cc_mode) {
case 1: case 1:
target_bitsize = calc_padding_cca(binary_length, *(cc_width)); target_bitsize = calc_padding_cca(binary_length, *(cc_width));
@ -1783,7 +1783,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
} }
binary_length = strlen(binary_string); binary_length = (int)strlen(binary_string);
switch (cc_mode) { switch (cc_mode) {
case 1: case 1:
target_bitsize = calc_padding_cca(binary_length, *(cc_width)); target_bitsize = calc_padding_cca(binary_length, *(cc_width));
@ -1825,55 +1825,6 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
return 0; return 0;
} }
void add_leading_zeroes(struct zint_symbol *symbol) {
int with_addon = 0;
int first_len = 0, second_len = 0, zfirst_len = 0, zsecond_len = 0, i, h, n = 0;
h = strlen(symbol->primary);
for (i = 0; i < h; i++) {
if (symbol->primary[i] == '+') {
with_addon = 1;
} else {
if (with_addon == 0) {
first_len++;
} else {
second_len++;
}
}
}
/* Calculate target lengths */
if (first_len <= 12) {
zfirst_len = 12;
}
if (first_len <= 7) {
zfirst_len = 7;
}
if (second_len <= 5) {
zsecond_len = 5;
}
if (second_len <= 2) {
zsecond_len = 2;
}
if (second_len == 0) {
zsecond_len = 0;
}
/* Add leading zeroes */
n = zfirst_len - first_len;
if (n > 0) {
memmove(symbol->primary + n, symbol->primary, h);
memset(symbol->primary, '0', n);
}
n += first_len + 1;
if (zsecond_len) {
memmove(symbol->primary + n + zsecond_len, symbol->primary + n, second_len);
memset(symbol->primary + n, '0', zsecond_len);
n += zsecond_len + second_len;
}
symbol->primary[n] = '\0';
}
int linear_dummy_run(unsigned char *source, int length) { int linear_dummy_run(unsigned char *source, int length) {
struct zint_symbol *dummy; struct zint_symbol *dummy;
int error_number; int error_number;
@ -1912,7 +1863,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Perform sanity checks on input options first */ /* Perform sanity checks on input options first */
error_number = 0; error_number = 0;
pri_len = strlen(symbol->primary); pri_len = (int)strlen(symbol->primary);
if (pri_len == 0) { if (pri_len == 0) {
strcpy(symbol->errtxt, "No primary (linear) message in 2D composite (D45)"); strcpy(symbol->errtxt, "No primary (linear) message in 2D composite (D45)");
return ZINT_ERROR_INVALID_OPTION; return ZINT_ERROR_INVALID_OPTION;

View File

@ -256,22 +256,22 @@ static void dminsert(char binary_string[], const int posn, const char newbit) {
binary_string[posn] = newbit; binary_string[posn] = newbit;
} }
static void insert_value(unsigned char binary_stream[], const int posn, const int streamlen, const int newbit) { static void insert_value(unsigned char binary_stream[], const int posn, const size_t streamlen, const int newbit) {
int i; int i;
for (i = streamlen; i > posn; i--) { for(i = (int)streamlen; i > posn; i--) {
binary_stream[i] = binary_stream[i - 1]; binary_stream[i] = binary_stream[i - 1];
} }
binary_stream[posn] = (unsigned char) newbit; binary_stream[posn] = (unsigned char) newbit;
} }
static int p_r_6_2_1(const unsigned char inputData[], const int position, const int sourcelen) { static int p_r_6_2_1(const unsigned char inputData[], const int position, const size_t sourcelen) {
/* Annex P section (r)(6)(ii)(I) /* Annex P section (r)(6)(ii)(I)
"If one of the three X12 terminator/separator characters first "If one of the three X12 terminator/separator characters first
occurs in the yet to be processed data before a non-X12 character..." occurs in the yet to be processed data before a non-X12 character..."
*/ */
int i; size_t i;
int nonX12Position = 0; int nonX12Position = 0;
int specialX12Position = 0; int specialX12Position = 0;
int retval = 0; int retval = 0;
@ -302,10 +302,11 @@ static int p_r_6_2_1(const unsigned char inputData[], const int position, const
} }
/* 'look ahead test' from Annex P */ /* 'look ahead test' from Annex P */
static int look_ahead_test(const unsigned char inputData[], const int sourcelen, const int position, const int current_mode, const int gs1) { static int look_ahead_test(const unsigned char inputData[], const size_t sourcelen, const size_t position, const int current_mode, const int gs1) {
float ascii_count, c40_count, text_count, x12_count, edf_count, b256_count, best_count; float ascii_count, c40_count, text_count, x12_count, edf_count, b256_count, best_count;
const float stiction = (1.0F / 24.0F); // smallest change to act on, to get around floating point inaccuracies const float stiction = (1.0F / 24.0F); // smallest change to act on, to get around floating point inaccuracies
int sp, best_scheme; int best_scheme;
size_t sp;
best_scheme = DM_NULL; best_scheme = DM_NULL;
@ -520,9 +521,6 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen,
} }
} }
//printf("Char %d[%c]: ASC:%.2f C40:%.2f X12:%.2f TXT:%.2f EDI:%.2f BIN:%.2f\n", sp,
// inputData[sp], ascii_count, c40_count, x12_count, text_count, edf_count, b256_count);
sp++; sp++;
} while (best_scheme == DM_NULL); // step (s) } while (best_scheme == DM_NULL); // step (s)
@ -531,11 +529,12 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen,
/* Encodes data using ASCII, C40, Text, X12, EDIFACT or Base 256 modes as appropriate /* Encodes data using ASCII, C40, Text, X12, EDIFACT or Base 256 modes as appropriate
Supports encoding FNC1 in supporting systems */ Supports encoding FNC1 in supporting systems */
static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], unsigned char target[], int *last_mode, int *length_p, int process_buffer[], int *process_p) { static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], unsigned char target[], int *last_mode, size_t *length_p, int process_buffer[], int *process_p) {
int sp, tp, i, gs1; size_t sp;
int tp, i, gs1;
int current_mode, next_mode; int current_mode, next_mode;
int inputlen = *length_p; size_t inputlen = *length_p;
int debug = symbol->debug; int debug = symbol->debug;
#ifndef _MSC_VER #ifndef _MSC_VER
char binary[2 * inputlen]; char binary[2 * inputlen];
@ -984,7 +983,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
return tp; return tp;
} }
static int dm200encode_remainder(unsigned char target[], int target_length, const unsigned char source[], const int inputlen, const int last_mode, const int process_buffer[], const int process_p, const int symbols_left) { static int dm200encode_remainder(unsigned char target[], int target_length, const unsigned char source[], const size_t inputlen, const int last_mode, const int process_buffer[], const int process_p, const int symbols_left) {
int debug = 0; int debug = 0;
switch (last_mode) { switch (last_mode) {
@ -1124,8 +1123,9 @@ static void add_tail(unsigned char target[], int tp, const int tail_length) {
} }
} }
int data_matrix_200(struct zint_symbol *symbol, const unsigned char source[], const int in_length) { int data_matrix_200(struct zint_symbol *symbol,const unsigned char source[], const size_t in_length) {
int i, inputlen = in_length, skew = 0; int i, skew = 0;
size_t inputlen=in_length;
unsigned char binary[2200]; unsigned char binary[2200];
int binlen; int binlen;
int process_buffer[8]; /* holds remaining data to finalised */ int process_buffer[8]; /* holds remaining data to finalised */
@ -1284,7 +1284,7 @@ int data_matrix_200(struct zint_symbol *symbol, const unsigned char source[], co
return error_number; return error_number;
} }
int dmatrix(struct zint_symbol *symbol, const unsigned char source[], const int in_length) { int dmatrix(struct zint_symbol *symbol, const unsigned char source[], const size_t in_length) {
int error_number; int error_number;
if (symbol->option_1 <= 1) { if (symbol->option_1 <= 1) {

View File

@ -44,7 +44,7 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
extern int data_matrix_200(struct zint_symbol *symbol, const unsigned char source[], const int length); extern int data_matrix_200(struct zint_symbol *symbol, const unsigned char source[], const size_t length);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -66,7 +66,7 @@ static const int dot_patterns[113] = {
0x1b8, 0x1c6, 0x1cc 0x1b8, 0x1c6, 0x1cc
}; };
int get_dot(char Dots[], int Hgt, int Wid, int x, int y) { static int get_dot(char Dots[], const int Hgt, const int Wid, const int x, const int y) {
int retval = 0; int retval = 0;
if ((x >= 0) && (x < Wid) && (y >= 0) && (y < Hgt)) { if ((x >= 0) && (x < Wid) && (y >= 0) && (y < Hgt)) {
@ -78,7 +78,7 @@ int get_dot(char Dots[], int Hgt, int Wid, int x, int y) {
return retval; return retval;
} }
int clr_col(char *Dots, int Hgt, int Wid, int x) { static int clr_col(char *Dots, const int Hgt, const int Wid, const int x) {
int y; int y;
for (y = x & 1; y < Hgt; y += 2) { for (y = x & 1; y < Hgt; y += 2) {
if (get_dot(Dots, Hgt, Wid, x, y)) { if (get_dot(Dots, Hgt, Wid, x, y)) {
@ -89,7 +89,7 @@ int clr_col(char *Dots, int Hgt, int Wid, int x) {
return 1; return 1;
} }
int clr_row(char *Dots, int Hgt, int Wid, int y) { static int clr_row(char *Dots, const int Hgt, const int Wid, const int y) {
int x; int x;
for (x = y & 1; x < Wid; x += 2) { for (x = y & 1; x < Wid; x += 2) {
if (get_dot(Dots, Hgt, Wid, x, y)) { if (get_dot(Dots, Hgt, Wid, x, y)) {
@ -101,7 +101,7 @@ int clr_row(char *Dots, int Hgt, int Wid, int y) {
} }
/* Dot pattern scoring routine from Annex A */ /* Dot pattern scoring routine from Annex A */
int score_array(char Dots[], int Hgt, int Wid) { const int score_array(char Dots[], int Hgt, int Wid) {
int x, y, worstedge, first, last, sum; int x, y, worstedge, first, last, sum;
int penalty_local = 0; int penalty_local = 0;
int penalty = 0; int penalty = 0;
@ -1192,9 +1192,9 @@ void fold_dotstream(char dot_stream[], int width, int height, char dot_array[])
int dotcode(struct zint_symbol *symbol, const unsigned char source[], int length) { int dotcode(struct zint_symbol *symbol, const unsigned char source[], int length) {
int i, j, k; int i, j, k;
size_t jc; size_t jc, n_dots;
int data_length, ecc_length; int data_length, ecc_length;
int min_dots, n_dots, min_area; int min_dots, min_area;
int height, width; int height, width;
int mask_score[4]; int mask_score[4];
int weight; int weight;

View File

@ -35,6 +35,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <malloc.h>
#include "common.h" #include "common.h"
#include "emf.h" #include "emf.h"

View File

@ -43,12 +43,12 @@
#include "gridmtx.h" #include "gridmtx.h"
#include "gb2312.h" #include "gb2312.h"
int number_lat(int gbdata[], int length, int position) { int number_lat(int gbdata[], const size_t length, const size_t position) {
/* Attempt to calculate the 'cost' of using numeric mode from a given position in number of bits */ /* Attempt to calculate the 'cost' of using numeric mode from a given position in number of bits */
/* Also ensures that numeric mode is not selected when it cannot be used: for example in /* Also ensures that numeric mode is not selected when it cannot be used: for example in
a string which has "2.2.0" (cannot have more than one non-numeric character for each a string which has "2.2.0" (cannot have more than one non-numeric character for each
block of three numeric characters) */ block of three numeric characters) */
int sp; size_t sp;
int numb = 0, nonum = 0, done; int numb = 0, nonum = 0, done;
int tally = 0; int tally = 0;
@ -118,14 +118,15 @@ int number_lat(int gbdata[], int length, int position) {
return tally; return tally;
} }
int seek_forward(int gbdata[], int length, int position, int current_mode) { static int seek_forward(int gbdata[], const size_t length, const size_t position, int current_mode) {
/* In complete contrast to the method recommended in Annex D of the ANSI standard this /* In complete contrast to the method recommended in Annex D of the ANSI standard this
code uses a look-ahead test in the same manner as Data Matrix. This decision was made code uses a look-ahead test in the same manner as Data Matrix. This decision was made
because the "official" algorithm does not provide clear methods for dealing with all because the "official" algorithm does not provide clear methods for dealing with all
possible combinations of input data */ possible combinations of input data */
int number_count, byte_count, mixed_count, upper_count, lower_count, chinese_count; int number_count, byte_count, mixed_count, upper_count, lower_count, chinese_count;
int sp, best_mode, done; int best_mode, done;
size_t sp;
int best_count, last = -1; int best_count, last = -1;
int debug = 0; int debug = 0;
@ -268,7 +269,7 @@ int seek_forward(int gbdata[], int length, int position, int current_mode) {
if (sp != last) { if (sp != last) {
if (((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) && ((gbdata[sp + 1] >= '0') && (gbdata[sp + 1] <= '9'))) { if (((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) && ((gbdata[sp + 1] >= '0') && (gbdata[sp + 1] <= '9'))) {
chinese_count -= 13; chinese_count -= 13;
last = sp + 1; last = (int)(sp + 1);
} }
} }
} }
@ -342,7 +343,7 @@ void add_shift_char(char binary[], int shifty) {
bin_append(glyph, 6, binary); bin_append(glyph, 6, binary);
} }
int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int debug) { static int gm_encode(int gbdata[], const size_t length, char binary[], int reader, int eci, int debug) {
/* Create a binary stream representation of the input data. /* Create a binary stream representation of the input data.
7 sets are defined - Chinese characters, Numerals, Lower case letters, Upper case letters, 7 sets are defined - Chinese characters, Numerals, Lower case letters, Upper case letters,
Mixed numerals and latters, Control characters and 8-bit binary data */ Mixed numerals and latters, Control characters and 8-bit binary data */
@ -987,7 +988,7 @@ void place_layer_id(char* grid, int size, int layers, int modules, int ecc_level
} }
} }
int grid_matrix(struct zint_symbol *symbol, const unsigned char source[], int length) { int grid_matrix(struct zint_symbol *symbol, const unsigned char source[], size_t length) {
int size, modules, dark, error_number; int size, modules, dark, error_number;
int auto_layers, min_layers, layers, auto_ecc_level, min_ecc_level, ecc_level; int auto_layers, min_layers, layers, auto_ecc_level, min_ecc_level, ecc_level;
int x, y, i, j, glyph; int x, y, i, j, glyph;
@ -1049,7 +1050,7 @@ int grid_matrix(struct zint_symbol *symbol, const unsigned char source[], int le
} }
/* Determine the size of the symbol */ /* Determine the size of the symbol */
data_cw = strlen(binary) / 7; data_cw = (int)strlen(binary) / 7;
auto_layers = 13; auto_layers = 13;
for (i = 12; i > 0; i--) { for (i = 12; i > 0; i--) {

View File

@ -64,7 +64,7 @@ int getsubmode(char input) {
} }
/* Calculate the approximate length of the binary string */ /* Calculate the approximate length of the binary string */
int calculate_binlength(char mode[], int source[], int length, int eci) { static int calculate_binlength(char mode[], int source[], const size_t length, int eci) {
int i; int i;
char lastmode = 't'; char lastmode = 't';
int est_binlen = 0; int est_binlen = 0;
@ -225,7 +225,7 @@ int isFourByte(int glyph, int glyph2) {
} }
/* Calculate mode switching */ /* Calculate mode switching */
void hx_define_mode(char mode[], int source[], int length) { static void hx_define_mode(char mode[], int source[], const size_t length) {
int i; int i;
char lastmode = 't'; char lastmode = 't';
int done; int done;
@ -329,7 +329,7 @@ int lookup_text2(char input) {
} }
/* Convert input data to binary stream */ /* Convert input data to binary stream */
void calculate_binary(char binary[], char mode[], int source[], int length, int eci, int debug) { static void calculate_binary(char binary[], char mode[], int source[], const size_t length, const int eci, int debug) {
int block_length; int block_length;
int position = 0; int position = 0;
int i, count, encoding_value; int i, count, encoding_value;
@ -1241,7 +1241,7 @@ int hx_apply_bitmask(unsigned char *grid, int size) {
} }
/* Han Xin Code - main */ /* Han Xin Code - main */
int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length) { int han_xin(struct zint_symbol *symbol, const unsigned char source[], size_t length) {
int est_binlen; int est_binlen;
int ecc_level = symbol->option_1; int ecc_level = symbol->option_1;
int i, j, version, posn = 0; int i, j, version, posn = 0;

View File

@ -171,7 +171,7 @@ short int islarger(short int accum[], short int reg[]) {
return larger; return larger;
} }
void binary_load(short int reg[], char data[], const unsigned int src_len) { void binary_load(short int reg[], char data[], const size_t src_len) {
int read, i; int read, i;
short int temp[112] = {0}; short int temp[112] = {0};

View File

@ -36,7 +36,7 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
extern void binary_load(short int reg[], char data[], const unsigned int src_len); extern void binary_load(short int reg[], char data[], const size_t src_len);
extern void binary_add(short int accumulator[], short int input_buffer[]); extern void binary_add(short int accumulator[], short int input_buffer[]);
extern void binary_subtract(short int accumulator[], short int input_buffer[]); extern void binary_subtract(short int accumulator[], short int input_buffer[]);
extern void shiftdown(short int buffer[]); extern void shiftdown(short int buffer[]);

View File

@ -162,13 +162,13 @@ extern int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
extern int dpleit(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Leitcode */ extern int dpleit(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Leitcode */
extern int dpident(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Identcode */ extern int dpident(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Identcode */
extern int c93(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 93 - a re-working of Code 39+, generates 2 check digits */ extern int c93(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 93 - a re-working of Code 39+, generates 2 check digits */
extern int code_128(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 128 and NVE-18 */ extern int code_128(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Code 128 and NVE-18 */
extern int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* EAN-128 (GS1-128) */ extern int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* EAN-128 (GS1-128) */
extern int code_11(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 11 */ extern int code_11(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 11 */
extern int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length); /* MSI Plessey */ extern int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length); /* MSI Plessey */
extern int telepen(struct zint_symbol *symbol, unsigned char source[], int length); /* Telepen ASCII */ extern int telepen(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Telepen ASCII */
extern int telepen_num(struct zint_symbol *symbol, unsigned char source[], int length); /* Telepen Numeric */ extern int telepen_num(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Telepen Numeric */
extern int plessey(struct zint_symbol *symbol, unsigned char source[], int length); /* Plessey Code */ extern int plessey(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Plessey Code */
extern int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmacode One Track */ extern int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmacode One Track */
extern int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length); /* Flattermarken */ extern int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length); /* Flattermarken */
extern int fim(struct zint_symbol *symbol, unsigned char source[], int length); /* Facing Identification Mark */ extern int fim(struct zint_symbol *symbol, unsigned char source[], int length); /* Facing Identification Mark */
@ -178,34 +178,34 @@ extern int planet_plot(struct zint_symbol *symbol, unsigned char source[], int l
extern int imail(struct zint_symbol *symbol, unsigned char source[], int length); /* Intelligent Mail (aka USPS OneCode) */ extern int imail(struct zint_symbol *symbol, unsigned char source[], int length); /* Intelligent Mail (aka USPS OneCode) */
extern int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length); /* RM4SCC */ extern int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length); /* RM4SCC */
extern int australia_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Australia Post 4-state */ extern int australia_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Australia Post 4-state */
extern int code16k(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 16k */ extern int code16k(struct zint_symbol *symbol, unsigned char source[],const size_t length); /* Code 16k */
extern int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length); /* PDF417 */ extern int pdf417enc(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* PDF417 */
extern int dmatrix(struct zint_symbol *symbol, const unsigned char source[], int length); /* Data Matrix (IEC16022) */ extern int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size_t length); /* Micro PDF417 */
extern int qr_code(struct zint_symbol *symbol, const unsigned char source[], int length); /* QR Code */
extern int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length); /* Micro PDF417 */
extern int maxicode(struct zint_symbol *symbol, unsigned char source[], int length); /* Maxicode */ extern int maxicode(struct zint_symbol *symbol, unsigned char source[], int length); /* Maxicode */
extern int rss14(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS-14 */ extern int rss14(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS-14 */
extern int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS Limited */ extern int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS Limited */
extern int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS Expanded */ extern int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS Expanded */
extern int composite(struct zint_symbol *symbol, unsigned char source[], int length); /* Composite Symbology */ extern int composite(struct zint_symbol *symbol, unsigned char source[], int length); /* Composite Symbology */
extern int kix_code(struct zint_symbol *symbol, unsigned char source[], int length); /* TNT KIX Code */ extern int kix_code(struct zint_symbol *symbol, unsigned char source[], int length); /* TNT KIX Code */
extern int aztec(struct zint_symbol *symbol, unsigned char source[], int length); /* Aztec Code */ extern int aztec(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Aztec Code */
extern int code32(struct zint_symbol *symbol, unsigned char source[], int length); /* Italian Pharmacode */ extern int code32(struct zint_symbol *symbol, unsigned char source[], int length); /* Italian Pharmacode */
extern int daft_code(struct zint_symbol *symbol, unsigned char source[], int length); /* DAFT Code */ extern int daft_code(struct zint_symbol *symbol, unsigned char source[], int length); /* DAFT Code */
extern int ean_14(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-14 */ extern int ean_14(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-14 */
extern int nve_18(struct zint_symbol *symbol, unsigned char source[], int length); /* NVE-18 */ extern int nve_18(struct zint_symbol *symbol, unsigned char source[], int length); /* NVE-18 */
extern int microqr(struct zint_symbol *symbol, const unsigned char source[], int length); /* Micro QR Code */ extern int microqr(struct zint_symbol *symbol, const unsigned char source[], size_t length); /* Micro QR Code */
extern int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length); /* Aztec Runes */ extern int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length); /* Aztec Runes */
extern int korea_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Korea Post */ extern int korea_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Korea Post */
extern int japan_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Japanese Post */ extern int japan_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Japanese Post */
extern int code_49(struct zint_symbol *symbol, unsigned char source[], const int length); /* Code 49 */ extern int code_49(struct zint_symbol *symbol, unsigned char source[], const int length); /* Code 49 */
extern int channel_code(struct zint_symbol *symbol, unsigned char source[], int length); /* Channel Code */ extern int channel_code(struct zint_symbol *symbol, unsigned char source[], int length); /* Channel Code */
extern int code_one(struct zint_symbol *symbol, unsigned char source[], int length); /* Code One */ extern int code_one(struct zint_symbol *symbol, unsigned char source[], int length); /* Code One */
extern int grid_matrix(struct zint_symbol *symbol, const unsigned char source[], int length); /* Grid Matrix */ extern int grid_matrix(struct zint_symbol *symbol, const unsigned char source[], size_t length); /* Grid Matrix */
extern int han_xin(struct zint_symbol * symbol, const unsigned char source[], int length); /* Han Xin */ extern int han_xin(struct zint_symbol * symbol, const unsigned char source[], size_t length); /* Han Xin */
extern int dotcode(struct zint_symbol * symbol, const unsigned char source[], int length); /* DotCode */ extern int dotcode(struct zint_symbol * symbol, const unsigned char source[], int length); /* DotCode */
extern int codablock(struct zint_symbol * symbol, unsigned char source[], int length); /* Codablock */ extern int codablock(struct zint_symbol * symbol, const unsigned char source[], const size_t length); /* Codablock */
extern int upnqr(struct zint_symbol *symbol, const unsigned char source[], int length); /* UPNQR */ extern int upnqr(struct zint_symbol *symbol, const unsigned char source[], int length); /* UPNQR */
extern int qr_code(struct zint_symbol *symbol, const unsigned char source[], size_t length); /* Data Matrix (IEC16022) */
extern int dmatrix(struct zint_symbol *symbol, const unsigned char source[], const size_t in_length); /* QR Code */
extern int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to PNG/BMP/PCX */ extern int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to PNG/BMP/PCX */
extern int render_plot(struct zint_symbol *symbol, float width, float height); /* Plot to gLabels */ extern int render_plot(struct zint_symbol *symbol, float width, float height); /* Plot to gLabels */
@ -285,7 +285,8 @@ int dump_plot(struct zint_symbol *symbol) {
/* Process health industry bar code data */ /* Process health industry bar code data */
static int hibc(struct zint_symbol *symbol, unsigned char source[], size_t length) { static int hibc(struct zint_symbol *symbol, unsigned char source[], size_t length) {
int counter, error_number, i; size_t i;
int counter, error_number;
char to_process[113], temp[2], check_digit; char to_process[113], temp[2], check_digit;
/* without "+" and check: max 110 characters in HIBC 2.6 */ /* without "+" and check: max 110 characters in HIBC 2.6 */
@ -812,17 +813,17 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
return error_number; return error_number;
} }
int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int length) { int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source,int in_length) {
int error_number, error_buffer, i; int error_number, error_buffer, i;
#ifdef _MSC_VER #ifdef _MSC_VER
unsigned char* local_source; unsigned char* local_source;
#endif #endif
error_number = 0; error_number = 0;
if (length == 0) { if (in_length == 0) {
length = (int) ustrlen(source); in_length = (int)ustrlen(source);
} }
if (length == 0) { if (in_length == 0) {
strcpy(symbol->errtxt, "No input data (B05)"); strcpy(symbol->errtxt, "No input data (B05)");
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_DATA); error_tag(symbol->errtxt, ZINT_ERROR_INVALID_DATA);
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
@ -836,9 +837,9 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
#endif #endif
} }
#ifndef _MSC_VER #ifndef _MSC_VER
unsigned char local_source[length + 1]; unsigned char local_source[in_length + 1];
#else #else
local_source = (unsigned char*) _alloca(length + 1); local_source = (unsigned char*) _alloca(in_length + 1);
#endif #endif
/* First check the symbology field */ /* First check the symbology field */
@ -992,25 +993,25 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
} }
if (symbol->input_mode == GS1_MODE) { if (symbol->input_mode == GS1_MODE) {
for (i = 0; i < length; i++) { for (i = 0; i < in_length; i++) {
if (source[i] == '\0') { if (source[i] == '\0') {
strcpy(symbol->errtxt, "NULL characters not permitted in GS1 mode (B19)"); strcpy(symbol->errtxt, "NULL characters not permitted in GS1 mode (B19)");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
} }
if (gs1_compliant(symbol->symbology) == 1) { if (gs1_compliant(symbol->symbology) == 1) {
error_number = ugs1_verify(symbol, source, length, local_source); error_number = ugs1_verify(symbol, source, in_length, local_source);
if (error_number != 0) { if (error_number != 0) {
return error_number; return error_number;
} }
length = ustrlen(local_source); in_length =(int)ustrlen(local_source);
} else { } else {
strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode (B20)"); strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode (B20)");
return ZINT_ERROR_INVALID_OPTION; return ZINT_ERROR_INVALID_OPTION;
} }
} else { } else {
memcpy(local_source, source, length); memcpy(local_source, source, in_length);
local_source[length] = '\0'; local_source[in_length] = '\0';
} }
if ((symbol->dot_size < 0.01) || (symbol->dot_size > 20.0)) { if ((symbol->dot_size < 0.01) || (symbol->dot_size > 20.0)) {
@ -1024,17 +1025,17 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
case BARCODE_GRIDMATRIX: case BARCODE_GRIDMATRIX:
case BARCODE_HANXIN: case BARCODE_HANXIN:
case BARCODE_UPNQR: case BARCODE_UPNQR:
error_number = extended_charset(symbol, local_source, length); error_number = extended_charset(symbol, local_source, in_length);
break; break;
default: default:
error_number = reduced_charset(symbol, local_source, length); error_number = reduced_charset(symbol, local_source, in_length);
break; break;
} }
if ((error_number == ZINT_ERROR_INVALID_DATA) && (supports_eci(symbol->symbology) if ((error_number == ZINT_ERROR_INVALID_DATA) && (supports_eci(symbol->symbology)
&& (symbol->input_mode == UNICODE_MODE))) { && (symbol->input_mode == UNICODE_MODE))) {
/* Try another ECI mode */ /* Try another ECI mode */
symbol->eci = get_best_eci(local_source, length); symbol->eci = get_best_eci(local_source, in_length);
error_number = ZINT_WARN_USES_ECI; error_number = ZINT_WARN_USES_ECI;
strcpy(symbol->errtxt, "Encoded data includes ECI codes (B22)"); strcpy(symbol->errtxt, "Encoded data includes ECI codes (B22)");
@ -1045,18 +1046,18 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
case BARCODE_MICROQR: case BARCODE_MICROQR:
case BARCODE_GRIDMATRIX: case BARCODE_GRIDMATRIX:
case BARCODE_HANXIN: case BARCODE_HANXIN:
error_number = utf_to_eci(symbol->eci, source, local_source, &length); error_number = utf_to_eci(symbol->eci, source, local_source, &in_length);
error_number = extended_charset(symbol, local_source, length); error_number = extended_charset(symbol, local_source, in_length);
break; break;
default: default:
error_number = reduced_charset(symbol, local_source, length); error_number = reduced_charset(symbol, local_source, in_length);
break; break;
} }
} }
if ((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) { if ((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) {
for (i = 0; i < length; i++) { for (i = 0; i < in_length; i++) {
if (local_source[i] == '\0') { if (local_source[i] == '\0') {
symbol->text[i] = ' '; symbol->text[i] = ' ';
} else { } else {

View File

@ -503,7 +503,8 @@ int maxi_text_process(int mode, unsigned char source[], int length, int eci) {
/* Format structured primary for Mode 2 */ /* Format structured primary for Mode 2 */
void maxi_do_primary_2(char postcode[], int country, int service) { void maxi_do_primary_2(char postcode[], int country, int service) {
int postcode_length, postcode_num, i; size_t postcode_length;
int postcode_num, i;
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
if ((postcode[i] < '0') || (postcode[i] > '9')) { if ((postcode[i] < '0') || (postcode[i] > '9')) {

View File

@ -557,7 +557,7 @@ void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int len
} }
/* 366 */ /* 366 */
int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) { static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size_t length) {
int i, k, j, indexchaine, indexliste, mode, longueur, loop, mccorrection[520], offset; int i, k, j, indexchaine, indexliste, mode, longueur, loop, mccorrection[520], offset;
int total, chainemc[2700], mclength, c1, c2, c3, dummy[35], codeerr; int total, chainemc[2700], mclength, c1, c2, c3, dummy[35], codeerr;
char codebarre[140], pattern[580]; char codebarre[140], pattern[580];
@ -670,7 +670,7 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) {
symbol->option_2 = 30; symbol->option_2 = 30;
} }
if (symbol->option_2 < 1) { if (symbol->option_2 < 1) {
symbol->option_2 = 0.5 + sqrt((longueur + k) / 3.0); symbol->option_2 =(int)(0.5 + sqrt((longueur + k) / 3.0));
} }
if (((longueur + k) / symbol->option_2) > 90) { if (((longueur + k) / symbol->option_2) > 90) {
/* stop the symbol from becoming too high */ /* stop the symbol from becoming too high */
@ -820,14 +820,14 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) {
} }
symbol->rows = (mclength / symbol->option_2); symbol->rows = (mclength / symbol->option_2);
symbol->width = strlen(pattern); symbol->width =(int)strlen(pattern);
/* 843 */ /* 843 */
return codeerr; return codeerr;
} }
/* 345 */ /* 345 */
int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) { int pdf417enc(struct zint_symbol *symbol, unsigned char source[], const size_t length) {
int codeerr, error_number; int codeerr, error_number;
error_number = 0; error_number = 0;
@ -877,7 +877,7 @@ int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) {
} }
/* like PDF417 only much smaller! */ /* like PDF417 only much smaller! */
int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) { int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size_t length) {
int i, k, j, indexchaine, indexliste, mode, longueur, mccorrection[50], offset; int i, k, j, indexchaine, indexliste, mode, longueur, mccorrection[50], offset;
int total, chainemc[2700], mclength, dummy[5], codeerr; int total, chainemc[2700], mclength, dummy[5], codeerr;
char codebarre[100], pattern[580]; char codebarre[100], pattern[580];

View File

@ -49,7 +49,7 @@ static const char *MSITable[10] = {
}; };
/* Not MSI/Plessey but the older Plessey standard */ /* Not MSI/Plessey but the older Plessey standard */
int plessey(struct zint_symbol *symbol, unsigned char source[], int length) { int plessey(struct zint_symbol *symbol, unsigned char source[], const size_t length) {
unsigned int i, check; unsigned int i, check;
unsigned char *checkptr; unsigned char *checkptr;
@ -110,9 +110,9 @@ int plessey(struct zint_symbol *symbol, unsigned char source[], int length) {
} }
/* Plain MSI Plessey - does not calculate any check character */ /* Plain MSI Plessey - does not calculate any check character */
int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length) { int msi_plessey(struct zint_symbol *symbol, unsigned char source[], const size_t length) {
unsigned int i; size_t i;
char dest[512]; /* 2 + 55 * 8 + 3 + 1 ~ 512 */ char dest[512]; /* 2 + 55 * 8 + 3 + 1 ~ 512 */
if (length > 55) { if (length > 55) {
@ -368,7 +368,8 @@ int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const
* Verified against http://www.bokai.com/BarcodeJSP/applet/BarcodeSampleApplet.htm */ * Verified against http://www.bokai.com/BarcodeJSP/applet/BarcodeSampleApplet.htm */
int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) { int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len) {
/* Weighted using the IBM system */ /* Weighted using the IBM system */
unsigned long i, weight, x, check, wright, dau, pedwar, pump, h; unsigned long i, weight, x, check, wright, dau, pedwar, pump;
size_t h;
long si; long si;
char un[16], tri[16]; char un[16], tri[16];
int error_number; int error_number;

View File

@ -45,7 +45,7 @@
extern int utf_to_eci(int eci, const unsigned char source[], unsigned char dest[], int *length); /* Convert Unicode to other encodings */ extern int utf_to_eci(int eci, const unsigned char source[], unsigned char dest[], int *length); /* Convert Unicode to other encodings */
/* Returns true if input glyph is in the Alphanumeric set */ /* Returns true if input glyph is in the Alphanumeric set */
int in_alpha(int glyph) { static int in_alpha(const int glyph) {
int retval = 0; int retval = 0;
char cglyph = (char) glyph; char cglyph = (char) glyph;
@ -72,9 +72,10 @@ int in_alpha(int glyph) {
return retval; return retval;
} }
void define_mode(char mode[], int jisdata[], int length, int gs1) { static void define_mode(char mode[],const int jisdata[], const size_t length,const int gs1) {
/* Values placed into mode[] are: K = Kanji, B = Binary, A = Alphanumeric, N = Numeric */ /* Values placed into mode[] are: K = Kanji, B = Binary, A = Alphanumeric, N = Numeric */
int i, mlen, j; size_t i;
int mlen, j;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (jisdata[i] > 0xff) { if (jisdata[i] > 0xff) {
@ -129,8 +130,9 @@ void define_mode(char mode[], int jisdata[], int length, int gs1) {
} }
/* Make an estimate (worst case scenario) of how long the binary string will be */ /* Make an estimate (worst case scenario) of how long the binary string will be */
int estimate_binary_length(char mode[], int length, int gs1, int eci) { static int estimate_binary_length(const char mode[], const size_t length,const int gs1,const int eci) {
int i, count = 0; size_t i;
int count = 0;
char current = 0; char current = 0;
int a_count = 0; int a_count = 0;
int n_count = 0; int n_count = 0;
@ -192,14 +194,14 @@ int estimate_binary_length(char mode[], int length, int gs1, int eci) {
return count; return count;
} }
static void qr_bscan(char *binary, int data, int h) { static void qr_bscan(char *binary,const int data,int h) {
for (; h; h >>= 1) { for (; h; h >>= 1) {
strcat(binary, data & h ? "1" : "0"); strcat(binary, data & h ? "1" : "0");
} }
} }
/* Convert input data to a binary stream and add padding */ /* Convert input data to a binary stream and add padding */
void qr_binary(int datastream[], int version, int target_binlen, char mode[], int jisdata[], int length, int gs1, int eci, int est_binlen, int debug) { static void qr_binary(int datastream[], const int version, const int target_binlen, const char mode[], const int jisdata[], const size_t length, const int gs1, const int eci, const int est_binlen, int debug) {
int position = 0; int position = 0;
int short_data_block_length, i, scheme = 1; int short_data_block_length, i, scheme = 1;
char data_block, padbits; char data_block, padbits;
@ -464,7 +466,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in
/* Terminator */ /* Terminator */
strcat(binary, "0000"); strcat(binary, "0000");
current_binlen = strlen(binary); current_binlen = (int)strlen(binary);
padbits = 8 - (current_binlen % 8); padbits = 8 - (current_binlen % 8);
if (padbits == 8) { if (padbits == 8) {
padbits = 0; padbits = 0;
@ -509,7 +511,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in
} }
/* Split data into blocks, add error correction and then interleave the blocks and error correction data */ /* Split data into blocks, add error correction and then interleave the blocks and error correction data */
void add_ecc(int fullstream[], int datastream[], int version, int data_cw, int blocks) { static void add_ecc(int fullstream[],const int datastream[],const int version,const int data_cw,const int blocks) {
int ecc_cw = qr_total_codewords[version - 1] - data_cw; int ecc_cw = qr_total_codewords[version - 1] - data_cw;
int short_data_block_length = data_cw / blocks; int short_data_block_length = data_cw / blocks;
int qty_long_blocks = data_cw % blocks; int qty_long_blocks = data_cw % blocks;
@ -598,10 +600,10 @@ void add_ecc(int fullstream[], int datastream[], int version, int data_cw, int b
} }
} }
void place_finder(unsigned char grid[], int size, int x, int y) { static void place_finder(unsigned char grid[],const int size,const int x,const int y) {
int xp, yp; int xp, yp;
int finder[] = { static const int finder[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1,
1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1,
@ -622,10 +624,10 @@ void place_finder(unsigned char grid[], int size, int x, int y) {
} }
} }
void place_align(unsigned char grid[], int size, int x, int y) { static void place_align(unsigned char grid[],const int size,int x,int y) {
int xp, yp; int xp, yp;
int alignment[] = { static const int alignment[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 0, 0, 1, 1, 0, 0, 0, 1,
1, 0, 1, 0, 1, 1, 0, 1, 0, 1,
@ -647,7 +649,7 @@ void place_align(unsigned char grid[], int size, int x, int y) {
} }
} }
void setup_grid(unsigned char* grid, int size, int version) { static void setup_grid(unsigned char* grid,const int size,const int version) {
int i, toggle = 1; int i, toggle = 1;
int loopsize, x, y, xcoord, ycoord; int loopsize, x, y, xcoord, ycoord;
@ -722,7 +724,7 @@ void setup_grid(unsigned char* grid, int size, int version) {
} }
} }
int cwbit(int* datastream, int i) { static int cwbit(const int* datastream,const int i) {
int resultant = 0; int resultant = 0;
if (datastream[(i / 8)] & (0x80 >> (i % 8))) { if (datastream[(i / 8)] & (0x80 >> (i % 8))) {
@ -732,7 +734,7 @@ int cwbit(int* datastream, int i) {
return resultant; return resultant;
} }
void populate_grid(unsigned char* grid, int size, int* datastream, int cw) { static void populate_grid(unsigned char* grid,const int size,const int* datastream,const int cw) {
int direction = 1; /* up */ int direction = 1; /* up */
int row = 0; /* right hand side */ int row = 0; /* right hand side */
@ -808,7 +810,7 @@ int write_log(char log[]) {
} }
#endif #endif
int evaluate(unsigned char *eval, int size, int pattern) { static int evaluate(unsigned char *eval,const int size,const int pattern) {
int x, y, block, weight; int x, y, block, weight;
int result = 0; int result = 0;
char state; char state;
@ -1056,7 +1058,7 @@ int evaluate(unsigned char *eval, int size, int pattern) {
return result; return result;
} }
void add_format_info_eval(unsigned char *eval, int size, int ecc_level, int pattern) { static void add_format_info_eval(unsigned char *eval,const int size,const int ecc_level,const int pattern) {
/* Add format information to grid */ /* Add format information to grid */
int format = pattern; int format = pattern;
@ -1095,7 +1097,7 @@ void add_format_info_eval(unsigned char *eval, int size, int ecc_level, int patt
eval[(8 * size) + 7] = (seq >> 8) & 0x01 ? (0x01 >> pattern) : 0x00; eval[(8 * size) + 7] = (seq >> 8) & 0x01 ? (0x01 >> pattern) : 0x00;
} }
int apply_bitmask(unsigned char *grid, int size, int ecc_level) { static int apply_bitmask(unsigned char *grid,const int size,const int ecc_level) {
int x, y; int x, y;
unsigned char p; unsigned char p;
int pattern, penalty[8]; int pattern, penalty[8];
@ -1199,7 +1201,7 @@ int apply_bitmask(unsigned char *grid, int size, int ecc_level) {
} }
/* Add format information to grid */ /* Add format information to grid */
void add_format_info(unsigned char *grid, int size, int ecc_level, int pattern) { static void add_format_info(unsigned char *grid,const int size,const int ecc_level,const int pattern) {
int format = pattern; int format = pattern;
unsigned int seq; unsigned int seq;
int i; int i;
@ -1237,7 +1239,7 @@ void add_format_info(unsigned char *grid, int size, int ecc_level, int pattern)
} }
/* Add version information */ /* Add version information */
void add_version_info(unsigned char *grid, int size, int version) { static void add_version_info(unsigned char *grid,const int size,const int version) {
int i; int i;
long int version_data = qr_annex_d[version - 7]; long int version_data = qr_annex_d[version - 7];
@ -1252,7 +1254,7 @@ void add_version_info(unsigned char *grid, int size, int version) {
} }
/* Choose from three numbers based on version */ /* Choose from three numbers based on version */
int tribus(int version, int a, int b, int c) { static int tribus(const int version,const int a,const int b,const int c) {
int RetVal; int RetVal;
RetVal = c; RetVal = c;
@ -1270,7 +1272,7 @@ int tribus(int version, int a, int b, int c) {
/* Implements a custom optimisation algorithm, more efficient than that /* Implements a custom optimisation algorithm, more efficient than that
given in Annex J. */ given in Annex J. */
void applyOptimisation(int version, char inputMode[], int inputLength) { static void applyOptimisation(const int version,char inputMode[], const size_t inputLength) {
int blockCount = 0, block; int blockCount = 0, block;
@ -1384,9 +1386,10 @@ void applyOptimisation(int version, char inputMode[], int inputLength) {
free(blockMode); free(blockMode);
} }
int blockLength(int start, char inputMode[], int inputLength) { static int blockLength(const int start,const char inputMode[],const size_t inputLength) {
/* Find the length of the block starting from 'start' */ /* Find the length of the block starting from 'start' */
int i, count; size_t i;
int count;
char mode = inputMode[start]; char mode = inputMode[start];
count = 0; count = 0;
@ -1399,10 +1402,11 @@ int blockLength(int start, char inputMode[], int inputLength) {
return count; return count;
} }
int getBinaryLength(int version, char inputMode[], int inputData[], int inputLength, int gs1, int eci) { static int getBinaryLength(const int version,char inputMode[],const int inputData[],const size_t inputLength,const int gs1,const int eci) {
/* Calculate the actual bitlength of the proposed binary string */ /* Calculate the actual bitlength of the proposed binary string */
size_t i;
char currentMode; char currentMode;
int i, j; int j;
int count = 0; int count = 0;
applyOptimisation(version, inputMode, inputLength); applyOptimisation(version, inputMode, inputLength);
@ -1471,8 +1475,9 @@ int getBinaryLength(int version, char inputMode[], int inputData[], int inputLen
return count; return count;
} }
int qr_code(struct zint_symbol *symbol, const unsigned char source[], int length) { int qr_code(struct zint_symbol *symbol, const unsigned char source[], size_t length) {
int error_number, i, j, glyph, est_binlen; int i, j, est_binlen;
int error_number,glyph;
int ecc_level, autosize, version, max_cw, target_binlen, blocks, size; int ecc_level, autosize, version, max_cw, target_binlen, blocks, size;
int bitmask, gs1; int bitmask, gs1;
int canShrink; int canShrink;
@ -1721,7 +1726,7 @@ int qr_code(struct zint_symbol *symbol, const unsigned char source[], int length
/* NOTE: From this point forward concerns Micro QR Code only */ /* NOTE: From this point forward concerns Micro QR Code only */
int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length, int *kanji_used, int *alphanum_used, int *byte_used, int debug) { static int micro_qr_intermediate(char binary[], const int jisdata[], const char mode[], const size_t length, int *kanji_used, int *alphanum_used, int *byte_used, int debug) {
/* Convert input data to an "intermediate stage" where data is binary encoded but /* Convert input data to an "intermediate stage" where data is binary encoded but
control information is not */ control information is not */
int position = 0; int position = 0;
@ -1940,8 +1945,9 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length,
return 0; return 0;
} }
void get_bitlength(int count[], char stream[]) { static void get_bitlength(int count[],const char stream[]) {
int length, i; size_t length;
int i;
length = strlen(stream); length = strlen(stream);
@ -1987,8 +1993,9 @@ void get_bitlength(int count[], char stream[]) {
} while (i < length); } while (i < length);
} }
void microqr_expand_binary(char binary_stream[], char full_stream[], int version) { static void microqr_expand_binary(const char binary_stream[], char full_stream[],const int version) {
int i, length; int i;
size_t length;
length = strlen(binary_stream); length = strlen(binary_stream);
@ -2070,7 +2077,7 @@ void microqr_expand_binary(char binary_stream[], char full_stream[], int version
} while (i < length); } while (i < length);
} }
void micro_qr_m1(char binary_data[]) { static void micro_qr_m1(char binary_data[]) {
int i, j, latch; int i, j, latch;
int bits_total, bits_left, remainder; int bits_total, bits_left, remainder;
int data_codewords, ecc_codewords; int data_codewords, ecc_codewords;
@ -2080,7 +2087,7 @@ void micro_qr_m1(char binary_data[]) {
latch = 0; latch = 0;
/* Add terminator */ /* Add terminator */
bits_left = bits_total - strlen(binary_data); bits_left = bits_total - (int)strlen(binary_data);
if (bits_left <= 3) { if (bits_left <= 3) {
for (i = 0; i < bits_left; i++) { for (i = 0; i < bits_left; i++) {
strcat(binary_data, "0"); strcat(binary_data, "0");
@ -2092,7 +2099,7 @@ void micro_qr_m1(char binary_data[]) {
if (latch == 0) { if (latch == 0) {
/* Manage last (4-bit) block */ /* Manage last (4-bit) block */
bits_left = bits_total - strlen(binary_data); bits_left = bits_total - (int)strlen(binary_data);
if (bits_left <= 4) { if (bits_left <= 4) {
for (i = 0; i < bits_left; i++) { for (i = 0; i < bits_left; i++) {
strcat(binary_data, "0"); strcat(binary_data, "0");
@ -2112,7 +2119,7 @@ void micro_qr_m1(char binary_data[]) {
} }
/* Add padding */ /* Add padding */
bits_left = bits_total - strlen(binary_data); bits_left = bits_total - (int)strlen(binary_data);
if (bits_left > 4) { if (bits_left > 4) {
remainder = (bits_left - 4) / 8; remainder = (bits_left - 4) / 8;
for (i = 0; i < remainder; i++) { for (i = 0; i < remainder; i++) {
@ -2153,10 +2160,10 @@ void micro_qr_m1(char binary_data[]) {
} }
} }
void micro_qr_m2(char binary_data[], int ecc_mode) { static void micro_qr_m2(char binary_data[],const int ecc_mode) {
int i, j, latch; int i, j, latch;
int bits_total, bits_left, remainder; int bits_total=0, bits_left, remainder;
int data_codewords, ecc_codewords; int data_codewords=0, ecc_codewords=0;
unsigned char data_blocks[6], ecc_blocks[7]; unsigned char data_blocks[6], ecc_blocks[7];
latch = 0; latch = 0;
@ -2164,12 +2171,13 @@ void micro_qr_m2(char binary_data[], int ecc_mode) {
if (ecc_mode == LEVEL_L) { if (ecc_mode == LEVEL_L) {
bits_total = 40; bits_total = 40;
} }
if (ecc_mode == LEVEL_M) { else if (ecc_mode == LEVEL_M) {
bits_total = 32; bits_total = 32;
} }
else assert(0);
/* Add terminator */ /* Add terminator */
bits_left = bits_total - strlen(binary_data); bits_left = bits_total - (int)strlen(binary_data);
if (bits_left <= 5) { if (bits_left <= 5) {
for (i = 0; i < bits_left; i++) { for (i = 0; i < bits_left; i++) {
strcat(binary_data, "0"); strcat(binary_data, "0");
@ -2190,7 +2198,7 @@ void micro_qr_m2(char binary_data[], int ecc_mode) {
} }
/* Add padding */ /* Add padding */
bits_left = bits_total - strlen(binary_data); bits_left = bits_total - (int)strlen(binary_data);
remainder = bits_left / 8; remainder = bits_left / 8;
for (i = 0; i < remainder; i++) { for (i = 0; i < remainder; i++) {
strcat(binary_data, i & 1 ? "00010001" : "11101100"); strcat(binary_data, i & 1 ? "00010001" : "11101100");
@ -2201,10 +2209,11 @@ void micro_qr_m2(char binary_data[], int ecc_mode) {
data_codewords = 5; data_codewords = 5;
ecc_codewords = 5; ecc_codewords = 5;
} }
if (ecc_mode == LEVEL_M) { else if (ecc_mode == LEVEL_M) {
data_codewords = 4; data_codewords = 4;
ecc_codewords = 6; ecc_codewords = 6;
} }
else assert(0);
/* Copy data into codewords */ /* Copy data into codewords */
for (i = 0; i < data_codewords; i++) { for (i = 0; i < data_codewords; i++) {
@ -2231,10 +2240,10 @@ void micro_qr_m2(char binary_data[], int ecc_mode) {
return; return;
} }
void micro_qr_m3(char binary_data[], int ecc_mode) { static void micro_qr_m3(char binary_data[],const int ecc_mode) {
int i, j, latch; int i, j, latch;
int bits_total, bits_left, remainder; int bits_total=0, bits_left, remainder;
int data_codewords, ecc_codewords; int data_codewords=0, ecc_codewords=0;
unsigned char data_blocks[12], ecc_blocks[9]; unsigned char data_blocks[12], ecc_blocks[9];
latch = 0; latch = 0;
@ -2242,12 +2251,13 @@ void micro_qr_m3(char binary_data[], int ecc_mode) {
if (ecc_mode == LEVEL_L) { if (ecc_mode == LEVEL_L) {
bits_total = 84; bits_total = 84;
} }
if (ecc_mode == LEVEL_M) { else if (ecc_mode == LEVEL_M) {
bits_total = 68; bits_total = 68;
} }
else assert(0);
/* Add terminator */ /* Add terminator */
bits_left = bits_total - strlen(binary_data); bits_left = bits_total - (int)strlen(binary_data);
if (bits_left <= 7) { if (bits_left <= 7) {
for (i = 0; i < bits_left; i++) { for (i = 0; i < bits_left; i++) {
strcat(binary_data, "0"); strcat(binary_data, "0");
@ -2259,7 +2269,7 @@ void micro_qr_m3(char binary_data[], int ecc_mode) {
if (latch == 0) { if (latch == 0) {
/* Manage last (4-bit) block */ /* Manage last (4-bit) block */
bits_left = bits_total - strlen(binary_data); bits_left = bits_total - (int)strlen(binary_data);
if (bits_left <= 4) { if (bits_left <= 4) {
for (i = 0; i < bits_left; i++) { for (i = 0; i < bits_left; i++) {
strcat(binary_data, "0"); strcat(binary_data, "0");
@ -2279,7 +2289,7 @@ void micro_qr_m3(char binary_data[], int ecc_mode) {
} }
/* Add padding */ /* Add padding */
bits_left = bits_total - strlen(binary_data); bits_left = bits_total - (int)strlen(binary_data);
if (bits_left > 4) { if (bits_left > 4) {
remainder = (bits_left - 4) / 8; remainder = (bits_left - 4) / 8;
for (i = 0; i < remainder; i++) { for (i = 0; i < remainder; i++) {
@ -2293,10 +2303,11 @@ void micro_qr_m3(char binary_data[], int ecc_mode) {
data_codewords = 11; data_codewords = 11;
ecc_codewords = 6; ecc_codewords = 6;
} }
if (ecc_mode == LEVEL_M) { else if (ecc_mode == LEVEL_M) {
data_codewords = 9; data_codewords = 9;
ecc_codewords = 8; ecc_codewords = 8;
} }
else assert(0);
/* Copy data into codewords */ /* Copy data into codewords */
for (i = 0; i < (data_codewords - 1); i++) { for (i = 0; i < (data_codewords - 1); i++) {
@ -2341,10 +2352,10 @@ void micro_qr_m3(char binary_data[], int ecc_mode) {
return; return;
} }
void micro_qr_m4(char binary_data[], int ecc_mode) { static void micro_qr_m4(char binary_data[],const int ecc_mode) {
int i, j, latch; int i, j, latch;
int bits_total, bits_left, remainder; int bits_total=0, bits_left, remainder;
int data_codewords, ecc_codewords; int data_codewords=0, ecc_codewords=0;
unsigned char data_blocks[17], ecc_blocks[15]; unsigned char data_blocks[17], ecc_blocks[15];
latch = 0; latch = 0;
@ -2352,15 +2363,16 @@ void micro_qr_m4(char binary_data[], int ecc_mode) {
if (ecc_mode == LEVEL_L) { if (ecc_mode == LEVEL_L) {
bits_total = 128; bits_total = 128;
} }
if (ecc_mode == LEVEL_M) { else if (ecc_mode == LEVEL_M) {
bits_total = 112; bits_total = 112;
} }
if (ecc_mode == LEVEL_Q) { else if (ecc_mode == LEVEL_Q) {
bits_total = 80; bits_total = 80;
} }
else assert(0);
/* Add terminator */ /* Add terminator */
bits_left = bits_total - strlen(binary_data); bits_left = bits_total - (int)strlen(binary_data);
if (bits_left <= 9) { if (bits_left <= 9) {
for (i = 0; i < bits_left; i++) { for (i = 0; i < bits_left; i++) {
strcat(binary_data, "0"); strcat(binary_data, "0");
@ -2381,7 +2393,7 @@ void micro_qr_m4(char binary_data[], int ecc_mode) {
} }
/* Add padding */ /* Add padding */
bits_left = bits_total - strlen(binary_data); bits_left = bits_total - (int)strlen(binary_data);
remainder = bits_left / 8; remainder = bits_left / 8;
for (i = 0; i < remainder; i++) { for (i = 0; i < remainder; i++) {
strcat(binary_data, i & 1 ? "00010001" : "11101100"); strcat(binary_data, i & 1 ? "00010001" : "11101100");
@ -2392,14 +2404,15 @@ void micro_qr_m4(char binary_data[], int ecc_mode) {
data_codewords = 16; data_codewords = 16;
ecc_codewords = 8; ecc_codewords = 8;
} }
if (ecc_mode == LEVEL_M) { else if (ecc_mode == LEVEL_M) {
data_codewords = 14; data_codewords = 14;
ecc_codewords = 10; ecc_codewords = 10;
} }
if (ecc_mode == LEVEL_Q) { else if (ecc_mode == LEVEL_Q) {
data_codewords = 10; data_codewords = 10;
ecc_codewords = 14; ecc_codewords = 14;
} }
else assert(0);
/* Copy data into codewords */ /* Copy data into codewords */
for (i = 0; i < data_codewords; i++) { for (i = 0; i < data_codewords; i++) {
@ -2424,7 +2437,7 @@ void micro_qr_m4(char binary_data[], int ecc_mode) {
} }
} }
void micro_setup_grid(unsigned char* grid, int size) { static void micro_setup_grid(unsigned char* grid,const int size) {
int i, toggle = 1; int i, toggle = 1;
/* Add timing patterns */ /* Add timing patterns */
@ -2459,11 +2472,11 @@ void micro_setup_grid(unsigned char* grid, int size) {
grid[(8 * size) + 8] += 20; grid[(8 * size) + 8] += 20;
} }
void micro_populate_grid(unsigned char* grid, int size, char full_stream[]) { static void micro_populate_grid(unsigned char* grid,const int size,const char full_stream[]) {
int direction = 1; /* up */ int direction = 1; /* up */
int row = 0; /* right hand side */ int row = 0; /* right hand side */
size_t n;
int i, n, x, y; int i,x, y;
n = strlen(full_stream); n = strlen(full_stream);
y = size - 1; y = size - 1;
@ -2511,7 +2524,7 @@ void micro_populate_grid(unsigned char* grid, int size, char full_stream[]) {
} while (i < n); } while (i < n);
} }
int micro_evaluate(unsigned char *grid, int size, int pattern) { static int micro_evaluate(const unsigned char *grid,const int size,const int pattern) {
int sum1, sum2, i, filter = 0, retval; int sum1, sum2, i, filter = 0, retval;
switch (pattern) { switch (pattern) {
@ -2545,7 +2558,7 @@ int micro_evaluate(unsigned char *grid, int size, int pattern) {
return retval; return retval;
} }
int micro_apply_bitmask(unsigned char *grid, int size) { static int micro_apply_bitmask(unsigned char *grid,const int size) {
int x, y; int x, y;
unsigned char p; unsigned char p;
int pattern, value[8]; int pattern, value[8];
@ -2627,11 +2640,13 @@ int micro_apply_bitmask(unsigned char *grid, int size) {
return best_pattern; return best_pattern;
} }
int microqr(struct zint_symbol *symbol, const unsigned char source[], int length) { int microqr(struct zint_symbol *symbol, const unsigned char source[], size_t length) {
int i, j, glyph, size; size_t i;
int j,size;
char binary_stream[200]; char binary_stream[200];
char full_stream[200]; char full_stream[200];
int utfdata[40]; int utfdata[40],glyph;
int jisdata[40]; int jisdata[40];
char mode[40]; char mode[40];
int error_number, kanji_used = 0, alphanum_used = 0, byte_used = 0; int error_number, kanji_used = 0, alphanum_used = 0, byte_used = 0;

View File

@ -116,7 +116,7 @@ void rs_init_code(const int nsym, int index) {
} }
} }
void rs_encode(const int len, const unsigned char *data, unsigned char *res) { void rs_encode(const size_t len,const unsigned char *data, unsigned char *res) {
int i, k, m; int i, k, m;
for (i = 0; i < rlen; i++) for (i = 0; i < rlen; i++)
res[i] = 0; res[i] = 0;

View File

@ -39,7 +39,7 @@ extern "C" {
extern void rs_init_gf(const int poly); extern void rs_init_gf(const int poly);
extern void rs_init_code(const int nsym,int index); extern void rs_init_code(const int nsym,int index);
extern void rs_encode(const int len,const unsigned char *data, unsigned char *res); extern void rs_encode(const size_t len,const unsigned char *data, unsigned char *res);
extern void rs_encode_long(const int len,const unsigned int *data, unsigned int *res); extern void rs_encode_long(const int len,const unsigned int *data, unsigned int *res);
extern void rs_free(void); extern void rs_free(void);

View File

@ -105,7 +105,7 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh
r = 0; r = 0;
/* Isolate add-on text */ /* Isolate add-on text */
if (is_extendable(symbol->symbology)) { if (is_extendable(symbol->symbology)) {
for (i = 0; i < ustrlen(symbol->text); i++) { for(i = 0; i < (int)ustrlen(symbol->text); i++) {
if (latch == 1) { if (latch == 1) {
addon[r] = symbol->text[i]; addon[r] = symbol->text[i];
r++; r++;
@ -208,7 +208,7 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh
} }
} }
total_symbol_width_x = main_symbol_width_x + addon_width_x; total_symbol_width_x = 0.0 + main_symbol_width_x + addon_width_x;
total_area_width_x = total_symbol_width_x + (2 * (symbol->border_width + symbol->whitespace_width)); total_area_width_x = total_symbol_width_x + (2 * (symbol->border_width + symbol->whitespace_width));
xoffset = symbol->border_width + symbol->whitespace_width; xoffset = symbol->border_width + symbol->whitespace_width;

View File

@ -56,7 +56,7 @@ static char *TeleTable[] = {
"3113111113", "11311111111111", "331111111111", "111113111113", "31111111111111", "111311111113", "131111111113" "3113111113", "11311111111111", "331111111111", "111113111113", "31111111111111", "111311111113", "131111111113"
}; };
int telepen(struct zint_symbol *symbol, unsigned char source[], int src_len) { int telepen(struct zint_symbol *symbol, unsigned char source[], const size_t src_len) {
unsigned int i, count, check_digit; unsigned int i, count, check_digit;
int error_number; int error_number;
char dest[512]; /*14 + 30 * 14 + 14 + 14 + 1 ~ 512 */ char dest[512]; /*14 + 30 * 14 + 14 + 14 + 1 ~ 512 */
@ -103,9 +103,10 @@ int telepen(struct zint_symbol *symbol, unsigned char source[], int src_len) {
return error_number; return error_number;
} }
int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len) { int telepen_num(struct zint_symbol *symbol, unsigned char source[], const size_t src_len) {
unsigned int i, count, check_digit, glyph; unsigned int count, check_digit, glyph;
int error_number, temp_length = src_len; int error_number;
size_t i,temp_length = src_len;
char dest[1024]; /* 14 + 60 * 14 + 14 + 14 + 1 ~ 1024 */ char dest[1024]; /* 14 + 60 * 14 + 14 + 14 + 1 ~ 1024 */
unsigned char temp[64]; unsigned char temp[64];

View File

@ -505,7 +505,7 @@ char isbn_check(unsigned char source[]) {
} }
/* Make an EAN-13 barcode from an SBN or ISBN */ /* Make an EAN-13 barcode from an SBN or ISBN */
int isbn(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char dest[]) { static int isbn(struct zint_symbol *symbol, unsigned char source[], const size_t src_len, char dest[]) {
int i, error_number; int i, error_number;
char check_digit; char check_digit;

View File

@ -261,7 +261,7 @@ extern "C" {
ZINT_EXTERN void ZBarcode_Clear(struct zint_symbol *symbol); ZINT_EXTERN void ZBarcode_Clear(struct zint_symbol *symbol);
ZINT_EXTERN void ZBarcode_Delete(struct zint_symbol *symbol); ZINT_EXTERN void ZBarcode_Delete(struct zint_symbol *symbol);
ZINT_EXTERN int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *input, int length); ZINT_EXTERN int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *input, int length);
ZINT_EXTERN int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename); ZINT_EXTERN int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename);
ZINT_EXTERN int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle); ZINT_EXTERN int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle);
ZINT_EXTERN int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle); ZINT_EXTERN int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);

View File

@ -573,7 +573,7 @@ int main(int argc, char **argv) {
/* Zero and negative values are not permitted */ /* Zero and negative values are not permitted */
fprintf(stderr, "Invalid dot radius value (A06)\n"); fprintf(stderr, "Invalid dot radius value (A06)\n");
fflush(stderr); fflush(stderr);
my_symbol->dot_size = 4.0 / 5.0; my_symbol->dot_size = 4.0F / 5.0F;
} }
} }
if (!strcmp(long_options[option_index].name, "border")) { if (!strcmp(long_options[option_index].name, "border")) {

View File

@ -177,6 +177,7 @@
<ClCompile Include="..\backend\dmatrix.c" /> <ClCompile Include="..\backend\dmatrix.c" />
<ClCompile Include="..\backend\dotcode.c" /> <ClCompile Include="..\backend\dotcode.c" />
<ClCompile Include="..\backend\eci.c" /> <ClCompile Include="..\backend\eci.c" />
<ClCompile Include="..\backend\emf.c" />
<ClCompile Include="..\backend\gif.c" /> <ClCompile Include="..\backend\gif.c" />
<ClCompile Include="..\backend\gridmtx.c" /> <ClCompile Include="..\backend\gridmtx.c" />
<ClCompile Include="..\backend\gs1.c" /> <ClCompile Include="..\backend\gs1.c" />
@ -199,6 +200,7 @@
<ClCompile Include="..\backend\rss.c" /> <ClCompile Include="..\backend\rss.c" />
<ClCompile Include="..\backend\svg.c" /> <ClCompile Include="..\backend\svg.c" />
<ClCompile Include="..\backend\telepen.c" /> <ClCompile Include="..\backend\telepen.c" />
<ClCompile Include="..\backend\tif.c" />
<ClCompile Include="..\backend\upcean.c" /> <ClCompile Include="..\backend\upcean.c" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -209,6 +211,7 @@
<ClInclude Include="..\backend\composite.h" /> <ClInclude Include="..\backend\composite.h" />
<ClInclude Include="..\backend\dm200.h" /> <ClInclude Include="..\backend\dm200.h" />
<ClInclude Include="..\backend\dmatrix.h" /> <ClInclude Include="..\backend\dmatrix.h" />
<ClInclude Include="..\backend\emf.h" />
<ClInclude Include="..\backend\font.h" /> <ClInclude Include="..\backend\font.h" />
<ClInclude Include="..\backend\gb2312.h" /> <ClInclude Include="..\backend\gb2312.h" />
<ClInclude Include="..\backend\gridmtx.h" /> <ClInclude Include="..\backend\gridmtx.h" />
@ -223,6 +226,7 @@
<ClInclude Include="..\backend\resource.h" /> <ClInclude Include="..\backend\resource.h" />
<ClInclude Include="..\backend\rss.h" /> <ClInclude Include="..\backend\rss.h" />
<ClInclude Include="..\backend\sjis.h" /> <ClInclude Include="..\backend\sjis.h" />
<ClInclude Include="..\backend\tif.h" />
<ClInclude Include="..\backend\zint.h" /> <ClInclude Include="..\backend\zint.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>