Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

[clang] Fix compiler warnings #194

Closed
wants to merge 1 commit into from
Closed

[clang] Fix compiler warnings #194

wants to merge 1 commit into from

Conversation

poussa
Copy link
Contributor

@poussa poussa commented Sep 19, 2016

Fix the number of clang compiler errors which are all of the same type:

passing 'int32_t *' (aka 'int *') to parameter
of type 'uint32_t *' (aka 'unsigned int *') converts between pointers to
integer types with different sign [-Wpointer-sign]

Signed-off-by: Sakari Poussa [email protected]

Fix the number of clang compiler errors which are all of the same type:

passing 'int32_t *' (aka 'int *') to parameter
      of type 'uint32_t *' (aka 'unsigned int *') converts between pointers to
      integer types with different sign [-Wpointer-sign]

Signed-off-by: Sakari Poussa <[email protected]>
@poussa
Copy link
Contributor Author

poussa commented Sep 19, 2016

@jprestwo PTAL and test that it does not effect the functionality. I did not have any code yet which I can test this with (so did no testing).

@@ -65,7 +65,7 @@ void zjs_add_event_listener(jerry_value_t obj, const char* event, jerry_value_t
event_obj = jerry_create_object();
}

int32_t callback_id = -1;
uint32_t callback_id = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't going to work. A callback ID of 0 is valid. -1 is invalid/error return code. All the callbacks are stored in a static array so unless we void out the 0th element (always) the only option is to treat -1 as the error return. That or make 0xFFFFFFFF the error return code, that way its still a uint32_t and we can just check for UINT32_MAX for example. So I am not sure of the best way to go from here, what/where exactly is the warning?

@grgustaf
Copy link
Contributor

@jprestwo, the problem must be that right after these we're doing zjs_obj_get_uint32(..., &callback_id) into an in32_t, which is sketchy.

@jprestwo
Copy link
Contributor

jprestwo commented Sep 19, 2016

Ya that must be it. The part that scares me is initializing callback_id to 0 instead of -1. The only solutions I can think of are checking for an error from zjs_obj_get_uint32(), changing callback's to have zero be invalid, or initializing callback_id to a very big number (which would also mean "invalid").

Looking at the actual implementation of zjs_obj_get_uint32(), we are just casting a double to a uint32_t anyways, which is just as bad as anywhere else. We could add a new API: zjs_obj_get_int32() which just does the same thing but cast to an int32_t instead. What about that?

@grgustaf
Copy link
Contributor

I wonder if it would make any sense to install a permanent "null" callback at id 0. Then 0 could be invalid, and if it ever gets called we could have a print() statement that would let us know.

I think the get_int32 function should be okay too. I haven't looked in detail but I'm not sure we would actually create events with a callback_id of -1 or would we have aborted the attempt to create them in that case?

@grgustaf
Copy link
Contributor

@jprestwo do you want to try to rework this patch and see if it still removes the errors for Sakari before we merge it?

@jprestwo
Copy link
Contributor

@poussa, @grgustaf , I have updated this change here: #206

@grgustaf
Copy link
Contributor

@poussa, I think you can close this in favor of James's PR #206

@grgustaf
Copy link
Contributor

It looks like we're nearing success on the alternate solution PR #206, so I'm closing this one.

@grgustaf grgustaf closed this Sep 23, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants