Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    Minor bug in BMI160-driver

    Minor bug in BMI160-driver

    arurke
    Established Member

    In trigger_foc(), https://github.com/BoschSensortec/BMI160_driver/blob/master/bmi160.c#L6313 , the foc_status variable is not initalized with a value. Since the call to get_foc_status() can return without writing to foc_status, it will contain garbage when it is evaluated at https://github.com/BoschSensortec/BMI160_driver/blob/master/bmi160.c#L6329

    10 REPLIES 10

    Minhwan
    Community Moderator
    Community Moderator

    Hello arurke, 

     

    First of all, thanks for posting 🙂 

    Since get_foc_status should get foc status, we don't need to initialize for foc_status variable. 

    And it gets foc status in get_foc_status function, it gets status value from BMI160_STATUS_ADDR address.

    https://github.com/BoschSensortec/BMI160_driver/blob/master/bmi160.c#L6264

    I don't think there is some bug, could you elaborate if you still have some quetsions? 

    Thanks, 

    arurke
    Established Member

    Since get_foc_status should get foc status, we don't need to initialize for foc_status variable. 

    get_foc_status() does not guarantee that it does get foc_status: If the condition at line L6271, https://github.com/BoschSensortec/BMI160_driver/blob/master/bmi160.c#L6271, evaluates to false, the function will return without doing anything to the foc_status variable which thus still will contain garbage.

    Minhwan
    Community Moderator
    Community Moderator

    Hello arurke, 

     

    I understood. You mean if get_foc_status returns false,  trigger_foc returns false without anything, right? 

    Yes, that's right. You can make while loop for trigger_foc, but we don't do that because some customer want to check the error code and handle differet way. 

    Therefore, if get_foc_status returns false, customer can notice that the application doesn't perform FOC properly. 

    Thanks,

     

    arurke
    Established Member

    Not sure if I understood your follow-up... Just to be very clear about the issue:

    1. Line 6316: foc_status is declared but not initialized

    2. Line 6326: get_foc_status() is called.

    3. Line 6271: The read fails so rslt is not BMI160_OK

    4. Line 6277: get_foc_status() returns. foc_status has not been assigned any value(!)

    5. Line 6327: foc_status is used in comparison. This is undefined behavior(!) since foc_status has not been initialized

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist