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

Be explicit about signedness of data in binary code representation. Some...

Be explicit about signedness of data in binary code representation. Some architectures, like ARM, differ in this respect.
parent 68f65845
No related branches found
No related tags found
No related merge requests found
...@@ -158,7 +158,7 @@ struct sieve_binary { ...@@ -158,7 +158,7 @@ struct sieve_binary {
/* Current block buffer: all emit and read functions act upon this buffer */ /* Current block buffer: all emit and read functions act upon this buffer */
buffer_t *data; buffer_t *data;
const char *code; const signed char *code;
size_t code_size; size_t code_size;
}; };
...@@ -1612,9 +1612,10 @@ void sieve_binary_emit_extension_object ...@@ -1612,9 +1612,10 @@ void sieve_binary_emit_extension_object
* Code retrieval * Code retrieval
*/ */
#define ADDR_CODE_AT(binary, address) (binary->code[*address]) #define ADDR_CODE_AT(binary, address) ((signed char) ((binary)->code[*address]))
#define ADDR_DATA_AT(binary, address) ((unsigned char) (binary->code[*address])) #define ADDR_DATA_AT(binary, address) ((unsigned char) ((binary)->code[*address]))
#define ADDR_BYTES_LEFT(binary, address) (binary->code_size - (*address)) #define ADDR_POINTER(binary, address) ((const char *) (&(binary)->code[*address]))
#define ADDR_BYTES_LEFT(binary, address) ((binary)->code_size - (*address))
#define ADDR_JUMP(address, offset) (*address) += offset #define ADDR_JUMP(address, offset) (*address) += offset
/* Literals */ /* Literals */
...@@ -1635,7 +1636,7 @@ bool sieve_binary_read_byte ...@@ -1635,7 +1636,7 @@ bool sieve_binary_read_byte
} }
bool sieve_binary_read_code bool sieve_binary_read_code
(struct sieve_binary *binary, sieve_size_t *address, int *code_r) (struct sieve_binary *binary, sieve_size_t *address, signed int *code_r)
{ {
if ( ADDR_BYTES_LEFT(binary, address) >= 1 ) { if ( ADDR_BYTES_LEFT(binary, address) >= 1 ) {
if ( code_r != NULL ) if ( code_r != NULL )
...@@ -1713,7 +1714,7 @@ bool sieve_binary_read_string ...@@ -1713,7 +1714,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_CODE_AT(binary, address), strlen); *str_r = t_str_new_const(ADDR_POINTER(binary, address), strlen);
ADDR_JUMP(address, strlen); ADDR_JUMP(address, strlen);
if ( ADDR_CODE_AT(binary, address) != 0 ) if ( ADDR_CODE_AT(binary, address) != 0 )
......
...@@ -162,7 +162,7 @@ void sieve_binary_emit_extension_object ...@@ -162,7 +162,7 @@ void sieve_binary_emit_extension_object
bool sieve_binary_read_byte bool sieve_binary_read_byte
(struct sieve_binary *binary, sieve_size_t *address, unsigned int *byte_r); (struct sieve_binary *binary, sieve_size_t *address, unsigned int *byte_r);
bool sieve_binary_read_code bool sieve_binary_read_code
(struct sieve_binary *binary, sieve_size_t *address, int *code_r); (struct sieve_binary *binary, sieve_size_t *address, signed int *code_r);
bool sieve_binary_read_offset bool sieve_binary_read_offset
(struct sieve_binary *binary, sieve_size_t *address, int *offset_r); (struct sieve_binary *binary, sieve_size_t *address, int *offset_r);
bool sieve_binary_read_integer bool sieve_binary_read_integer
......
...@@ -266,7 +266,7 @@ bool sieve_operand_optional_present ...@@ -266,7 +266,7 @@ bool sieve_operand_optional_present
} }
bool sieve_operand_optional_read bool sieve_operand_optional_read
(struct sieve_binary *sbin, sieve_size_t *address, int *id_code) (struct sieve_binary *sbin, sieve_size_t *address, signed int *id_code)
{ {
if ( sieve_binary_read_code(sbin, address, id_code) ) if ( sieve_binary_read_code(sbin, address, id_code) )
return TRUE; return TRUE;
......
...@@ -70,7 +70,8 @@ const struct sieve_operand *sieve_operand_read ...@@ -70,7 +70,8 @@ const struct sieve_operand *sieve_operand_read
bool sieve_operand_optional_present bool sieve_operand_optional_present
(struct sieve_binary *sbin, sieve_size_t *address); (struct sieve_binary *sbin, sieve_size_t *address);
bool sieve_operand_optional_read bool sieve_operand_optional_read
(struct sieve_binary *sbin, sieve_size_t *address, int *id_code); (struct sieve_binary *sbin, sieve_size_t *address,
signed int *id_code);
/* /*
* Core operands * Core operands
......
...@@ -384,7 +384,7 @@ int sieve_interpreter_handle_optional_operands ...@@ -384,7 +384,7 @@ int sieve_interpreter_handle_optional_operands
(const struct sieve_runtime_env *renv, sieve_size_t *address, (const struct sieve_runtime_env *renv, sieve_size_t *address,
struct sieve_side_effects_list **list) struct sieve_side_effects_list **list)
{ {
int opt_code = -1; signed int opt_code = -1;
if ( sieve_operand_optional_present(renv->sbin, address) ) { if ( sieve_operand_optional_present(renv->sbin, address) ) {
while ( opt_code != 0 ) { while ( opt_code != 0 ) {
......
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.