Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent attempt to write write_cmos_register() if read_cmos_register() failed #367

Closed
wants to merge 1 commit into from
Closed

Conversation

maksqwe
Copy link

@maksqwe maksqwe commented Feb 8, 2014

uint16_t reg = read_cmos_register(dev, 0x0106);
if (reg < 0)

'reg' never be < 0. If read_cmos_register() failed it return value < 0, reg = 0xffff - err_value + 1

In read_cmos_register() send_cmd() if failed can return -1 or LIBUSB_ERROR_OTHER(-99) therefore read_cmos_register() must return only -1 if failed for correct result check

…) failed

uint16_t reg = read_cmos_register(dev, 0x0106);
if (reg < 0)

'reg' never be < 0. If read_cmos_register() failed it return value < 0, reg = 0xffff - err_value - 1

In read_cmos_register() send_cmd() if failed can return -1 or LIBUSB_ERROR_OTHER(-99) therefore read_cmos_register() must return only -1 if failed for correct result check
@piedar piedar added this to the v0.4.1 milestone Feb 12, 2014
@piedar
Copy link
Contributor

piedar commented Feb 16, 2014

This is definitely a bug, but I don't think your solution works either because it compares a uint16_t with -1, which will never be true:

#include <stdint.h>
#include <stdio.h>

int main()
{
    uint16_t foo = -1;
    if (foo == -1)
        printf("Never true!\n");

    return 0;
}

I made read_register() and read_cmos_register() return UINT16_MAX on error. It's not perfect, but it's better than the alternatives:

  1. Pass in an int* error parameter. (yuck)
  2. Return an int32_t and require a cast to get the actual value. (double-yuck)

@piedar piedar closed this in 7c0fcdf Feb 16, 2014
@maksqwe maksqwe deleted the set_flag_fix branch February 16, 2014 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants