greiman / SdFat-beta

Beta SdFat for test of new features
MIT License
166 stars 62 forks source link

Warning "'next' may be used uninitialized in this function" #72

Closed FrankBoesing closed 3 years ago

FrankBoesing commented 3 years ago

https://github.com/greiman/SdFat-beta/blob/790dd84e26e2b7a7bd91d3ee355a4b2855694db5/src/ExFatLib/ExFatPartition.cpp#L225

GCC 10 prints the mentioned warning.

greiman commented 3 years ago

next should be set at line 225 by this if status is one.

    status = fatGet(cluster, &next);
    if (status < 0) {
      DBG_FAIL_MACRO;
      goto fail;
    }

I will double check fatGet since is may have a problem.

greiman commented 3 years ago

It appears the program works OK but I made two changes that may suppress the warning.

First the return type of fatGet is wrong. it should be int8_t but all calls use int8_t for tests.

next is not used unless the return status is one. I changed this test to not use next unless status is one.

if (status == 0 || (cluster + 1) != next) {

I should probably change the loop to not execute these assigns before returning.

      start = next;
    }
    cluster = next;
  } while (status);

I did change fatGet to set next to EOC for return 0 so the compiler should not give the warning. If EOC is used, a crash or error will occur.

FrankBoesing commented 3 years ago

Thank you, Bill !