Skip to content

Commit 1aad423

Browse files
authored
bindings: ruby: fix unexpected uc_query result pointer type (#1962)
uc_query expects a size_t *, while we are passing uc_arch *. This has been working for a while as gcc just warned about this, however with latest gcc this changed into an error: unicorn.c:122:34: error: passing argument 3 of ‘uc_query’ from incompatible pointer type [-Wincompatible-pointer-types] 206 | uc_query(_uc, UC_QUERY_ARCH, &arch); unicorn.h:689:60: note: expected ‘size_t *’ {aka ‘long unsigned int *’} but argument is of type ‘uc_arch *’ 689 | uc_err uc_query(uc_engine *uc, uc_query_type type, size_t *result); Fix this issue by querying the result into a size_t and later downcast the result into an uc_arch enum.
1 parent f59d5aa commit 1aad423

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

bindings/ruby/unicorn_gem/ext/unicorn.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ VALUE m_uc_reg_read(VALUE self, VALUE reg_id){
118118
uc_engine *_uc;
119119
Data_Get_Struct(rb_iv_get(self,"@uch"), uc_engine, _uc);
120120

121-
uc_arch arch;
122-
uc_query(_uc, UC_QUERY_ARCH, &arch);
121+
size_t arch_result;
122+
uc_query(_uc, UC_QUERY_ARCH, &arch_result);
123+
uc_arch arch = (uc_arch) arch_result;
123124

124125
if(arch == UC_ARCH_X86) {
125126
switch(tmp_reg){
@@ -202,8 +203,9 @@ VALUE m_uc_reg_write(VALUE self, VALUE reg_id, VALUE reg_value){
202203
uc_engine *_uc;
203204
Data_Get_Struct(rb_iv_get(self,"@uch"), uc_engine, _uc);
204205

205-
uc_arch arch;
206-
uc_query(_uc, UC_QUERY_ARCH, &arch);
206+
size_t arch_result;
207+
uc_query(_uc, UC_QUERY_ARCH, &arch_result);
208+
uc_arch arch = (uc_arch) arch_result;
207209

208210
if(arch == UC_ARCH_X86) {
209211
switch(tmp_reg){

0 commit comments

Comments
 (0)