Use local variables when R and W pointers are used in same function
@@ -313,16 +313,19 @@ esp_buff_get_linear_block_address(esp_buff_t* buff) {
*/
size_t
esp_buff_get_linear_block_length(esp_buff_t* buff) {
- size_t len;
+ size_t w, r, len;
if (buff == NULL) {
return 0;
}
- if (buff->w > buff->r) {
- len = buff->w - buff->r;
- } else if (buff->r > buff->w) {
- len = buff->size - buff->r;
+ /* Operate on temporary values in case they change in between */
+ w = buff->w;
+ r = buff->r;
+ if (w > r) {
+ len = w - r;
+ } else if (r > w) {
+ len = buff->size - r;
} else {
len = 0;
}
