Skip to content
Snippets Groups Projects
Commit b9be8e38 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Sieve binary: now using better defined integer types for byte-coded data

parent 9e63fecd
No related branches found
No related tags found
No related merge requests found
...@@ -240,7 +240,7 @@ struct sieve_variable_scope *sieve_variable_scope_binary_dump ...@@ -240,7 +240,7 @@ struct sieve_variable_scope *sieve_variable_scope_binary_dump
struct sieve_variable_scope *local_scope; struct sieve_variable_scope *local_scope;
unsigned int i, scope_size; unsigned int i, scope_size;
sieve_size_t pc; sieve_size_t pc;
int end_offset; sieve_offset_t end_offset;
/* Read scope size */ /* Read scope size */
sieve_code_mark(denv); sieve_code_mark(denv);
...@@ -310,7 +310,7 @@ struct sieve_variable_scope_binary *sieve_variable_scope_binary_read ...@@ -310,7 +310,7 @@ struct sieve_variable_scope_binary *sieve_variable_scope_binary_read
const char *ext_name = const char *ext_name =
( ext == NULL ? "variables" : sieve_extension_name(ext) ); ( ext == NULL ? "variables" : sieve_extension_name(ext) );
sieve_size_t pc; sieve_size_t pc;
int end_offset; sieve_offset_t end_offset;
/* Read scope size */ /* Read scope size */
if ( !sieve_binary_read_unsigned(sblock, address, &scope_size) ) { if ( !sieve_binary_read_unsigned(sblock, address, &scope_size) ) {
......
...@@ -38,7 +38,7 @@ static inline void _sieve_binary_emit_data ...@@ -38,7 +38,7 @@ static inline void _sieve_binary_emit_data
} }
static inline void _sieve_binary_emit_byte static inline void _sieve_binary_emit_byte
(struct sieve_binary_block *sblock, unsigned char byte) (struct sieve_binary_block *sblock, uint8_t byte)
{ {
_sieve_binary_emit_data(sblock, &byte, 1); _sieve_binary_emit_data(sblock, &byte, 1);
} }
...@@ -61,7 +61,7 @@ sieve_size_t sieve_binary_emit_data ...@@ -61,7 +61,7 @@ sieve_size_t sieve_binary_emit_data
} }
sieve_size_t sieve_binary_emit_byte sieve_size_t sieve_binary_emit_byte
(struct sieve_binary_block *sblock, unsigned char byte) (struct sieve_binary_block *sblock, uint8_t byte)
{ {
sieve_size_t address = _sieve_binary_block_get_size(sblock); sieve_size_t address = _sieve_binary_block_get_size(sblock);
...@@ -80,13 +80,13 @@ void sieve_binary_update_data ...@@ -80,13 +80,13 @@ void sieve_binary_update_data
/* Offset emission functions */ /* Offset emission functions */
sieve_size_t sieve_binary_emit_offset sieve_size_t sieve_binary_emit_offset
(struct sieve_binary_block *sblock, int offset) (struct sieve_binary_block *sblock, sieve_offset_t offset)
{ {
int i; int i;
sieve_size_t address = _sieve_binary_block_get_size(sblock); sieve_size_t address = _sieve_binary_block_get_size(sblock);
for ( i = 3; i >= 0; i-- ) { for ( i = 3; i >= 0; i-- ) {
char c = (char) (offset >> (i * 8)); uint8_t c = (uint8_t) (offset >> (i * 8));
_sieve_binary_emit_data(sblock, &c, 1); _sieve_binary_emit_data(sblock, &c, 1);
} }
...@@ -97,10 +97,10 @@ void sieve_binary_resolve_offset ...@@ -97,10 +97,10 @@ void sieve_binary_resolve_offset
(struct sieve_binary_block *sblock, sieve_size_t address) (struct sieve_binary_block *sblock, sieve_size_t address)
{ {
int i; int i;
int offset = _sieve_binary_block_get_size(sblock) - address; sieve_offset_t offset = _sieve_binary_block_get_size(sblock) - address;
for ( i = 3; i >= 0; i-- ) { for ( i = 3; i >= 0; i-- ) {
char c = (char) (offset >> (i * 8)); uint8_t c = (uint8_t) (offset >> (i * 8));
_sieve_binary_update_data(sblock, address + 3 - i, &c, 1); _sieve_binary_update_data(sblock, address + 3 - i, &c, 1);
} }
} }
...@@ -112,7 +112,7 @@ sieve_size_t sieve_binary_emit_integer ...@@ -112,7 +112,7 @@ sieve_size_t sieve_binary_emit_integer
{ {
sieve_size_t address = _sieve_binary_block_get_size(sblock); sieve_size_t address = _sieve_binary_block_get_size(sblock);
int i; int i;
char buffer[sizeof(sieve_number_t) + 1]; uint8_t buffer[sizeof(sieve_number_t) + 1];
int bufpos = sizeof(buffer) - 1; int bufpos = sizeof(buffer) - 1;
buffer[bufpos] = integer & 0x7F; buffer[bufpos] = integer & 0x7F;
...@@ -201,14 +201,14 @@ void sieve_binary_emit_extension_object ...@@ -201,14 +201,14 @@ void sieve_binary_emit_extension_object
#define ADDR_CODE_READ(block) \ #define ADDR_CODE_READ(block) \
size_t _code_size; \ size_t _code_size; \
const signed char *_code = buffer_get_data((block)->data, &_code_size) const int8_t *_code = buffer_get_data((block)->data, &_code_size)
#define ADDR_CODE_AT(address) \ #define ADDR_CODE_AT(address) \
((signed char) (_code[*address])) ((int8_t) (_code[*address]))
#define ADDR_DATA_AT(address) \ #define ADDR_DATA_AT(address) \
((unsigned char) (_code[*address])) ((uint8_t) (_code[*address]))
#define ADDR_POINTER(address) \ #define ADDR_POINTER(address) \
((const char *) (&_code[*address])) ((const int8_t *) (&_code[*address]))
#define ADDR_BYTES_LEFT(address) \ #define ADDR_BYTES_LEFT(address) \
((_code_size) - (*address)) ((_code_size) - (*address))
...@@ -253,9 +253,9 @@ bool sieve_binary_read_code ...@@ -253,9 +253,9 @@ bool sieve_binary_read_code
bool sieve_binary_read_offset bool sieve_binary_read_offset
(struct sieve_binary_block *sblock, sieve_size_t *address, int *offset_r) (struct sieve_binary_block *sblock, sieve_size_t *address, sieve_offset_t *offset_r)
{ {
uint32_t offs = 0; sieve_offset_t offs = 0;
ADDR_CODE_READ(sblock); ADDR_CODE_READ(sblock);
if ( ADDR_BYTES_LEFT(address) >= 4 ) { if ( ADDR_BYTES_LEFT(address) >= 4 ) {
...@@ -267,7 +267,7 @@ bool sieve_binary_read_offset ...@@ -267,7 +267,7 @@ bool sieve_binary_read_offset
} }
if ( offset_r != NULL ) if ( offset_r != NULL )
*offset_r = (int) offs; *offset_r = offs;
return TRUE; return TRUE;
} }
...@@ -320,7 +320,7 @@ bool sieve_binary_read_string ...@@ -320,7 +320,7 @@ bool sieve_binary_read_string
return FALSE; return FALSE;
if ( str_r != NULL ) if ( str_r != NULL )
*str_r = t_str_new_const(ADDR_POINTER(address), strlen); *str_r = t_str_new_const((const char *) ADDR_POINTER(address), strlen);
ADDR_JUMP(address, strlen); ADDR_JUMP(address, strlen);
if ( ADDR_CODE_AT(address) != 0 ) if ( ADDR_CODE_AT(address) != 0 )
......
...@@ -148,7 +148,7 @@ int sieve_binary_extensions_count(struct sieve_binary *sbin); ...@@ -148,7 +148,7 @@ int sieve_binary_extensions_count(struct sieve_binary *sbin);
sieve_size_t sieve_binary_emit_data sieve_size_t sieve_binary_emit_data
(struct sieve_binary_block *sblock, const void *data, sieve_size_t size); (struct sieve_binary_block *sblock, const void *data, sieve_size_t size);
sieve_size_t sieve_binary_emit_byte sieve_size_t sieve_binary_emit_byte
(struct sieve_binary_block *sblock, unsigned char byte); (struct sieve_binary_block *sblock, uint8_t byte);
void sieve_binary_update_data void sieve_binary_update_data
(struct sieve_binary_block *sblock, sieve_size_t address, const void *data, (struct sieve_binary_block *sblock, sieve_size_t address, const void *data,
sieve_size_t size); sieve_size_t size);
...@@ -156,7 +156,7 @@ void sieve_binary_update_data ...@@ -156,7 +156,7 @@ void sieve_binary_update_data
/* Offset emission functions */ /* Offset emission functions */
sieve_size_t sieve_binary_emit_offset sieve_size_t sieve_binary_emit_offset
(struct sieve_binary_block *sblock, int offset); (struct sieve_binary_block *sblock, sieve_offset_t offset);
void sieve_binary_resolve_offset void sieve_binary_resolve_offset
(struct sieve_binary_block *sblock, sieve_size_t address); (struct sieve_binary_block *sblock, sieve_size_t address);
...@@ -198,7 +198,7 @@ bool sieve_binary_read_code ...@@ -198,7 +198,7 @@ bool sieve_binary_read_code
signed int *code_r); signed int *code_r);
bool sieve_binary_read_offset bool sieve_binary_read_offset
(struct sieve_binary_block *sblock, sieve_size_t *address, (struct sieve_binary_block *sblock, sieve_size_t *address,
int *offset_r); sieve_offset_t *offset_r);
bool sieve_binary_read_integer bool sieve_binary_read_integer
(struct sieve_binary_block *sblock, sieve_size_t *address, (struct sieve_binary_block *sblock, sieve_size_t *address,
sieve_number_t *int_r); sieve_number_t *int_r);
......
...@@ -765,7 +765,7 @@ static bool opr_stringlist_dump ...@@ -765,7 +765,7 @@ static bool opr_stringlist_dump
sieve_size_t pc = *address; sieve_size_t pc = *address;
sieve_size_t end; sieve_size_t end;
unsigned int length = 0; unsigned int length = 0;
int end_offset; sieve_offset_t end_offset;
if ( !sieve_binary_read_offset(denv->sblock, address, &end_offset) ) if ( !sieve_binary_read_offset(denv->sblock, address, &end_offset) )
return FALSE; return FALSE;
...@@ -785,7 +785,7 @@ static struct sieve_stringlist *opr_stringlist_read ...@@ -785,7 +785,7 @@ static struct sieve_stringlist *opr_stringlist_read
sieve_size_t pc = *address; sieve_size_t pc = *address;
sieve_size_t end; sieve_size_t end;
unsigned int length = 0; unsigned int length = 0;
int end_offset; sieve_offset_t end_offset;
if ( !sieve_binary_read_offset(renv->sblock, address, &end_offset) ) if ( !sieve_binary_read_offset(renv->sblock, address, &end_offset) )
return NULL; return NULL;
...@@ -1022,7 +1022,7 @@ static bool opc_jmp_dump ...@@ -1022,7 +1022,7 @@ static bool opc_jmp_dump
{ {
const struct sieve_operation *oprtn = denv->oprtn; const struct sieve_operation *oprtn = denv->oprtn;
unsigned int pc = *address; unsigned int pc = *address;
int offset; sieve_offset_t offset;
if ( sieve_binary_read_offset(denv->sblock, address, &offset) ) if ( sieve_binary_read_offset(denv->sblock, address, &offset) )
sieve_code_dumpf(denv, "%s %d [%08x]", sieve_code_dumpf(denv, "%s %d [%08x]",
......
...@@ -413,7 +413,7 @@ int sieve_interpreter_program_jump ...@@ -413,7 +413,7 @@ int sieve_interpreter_program_jump
const struct sieve_runtime_env *renv = &interp->runenv; const struct sieve_runtime_env *renv = &interp->runenv;
sieve_size_t *address = &(interp->runenv.pc); sieve_size_t *address = &(interp->runenv.pc);
sieve_size_t jmp_start = *address; sieve_size_t jmp_start = *address;
int jmp_offset; sieve_offset_t jmp_offset;
if ( !sieve_binary_read_offset(renv->sblock, address, &jmp_offset) ) if ( !sieve_binary_read_offset(renv->sblock, address, &jmp_offset) )
{ {
......
...@@ -105,7 +105,7 @@ static bool cmd_test_fail_operation_dump ...@@ -105,7 +105,7 @@ static bool cmd_test_fail_operation_dump
(const struct sieve_dumptime_env *denv, sieve_size_t *address) (const struct sieve_dumptime_env *denv, sieve_size_t *address)
{ {
unsigned int pc; unsigned int pc;
int offset; sieve_offset_t offset;
sieve_code_dumpf(denv, "TEST_FAIL:"); sieve_code_dumpf(denv, "TEST_FAIL:");
sieve_code_descend(denv); sieve_code_descend(denv);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.