Go Down

Topic: Compile warning using SD library - unused variable (Read 813 times) previous topic - next topic

Hal_cat

Possibly not a major problem, generates noise in the compile output
but does it indicate some missing error checks?

/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/SdFile.cpp: In static member function 'static uint8_t SdFile::make83Name(const char*, uint8_t*)':
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/SdFile.cpp:261:15: warning: unused variable 'b' [-Wunused-variable]
       uint8_t b;

from SdFile.cpp (just the function with the warning):

// format directory name field from a 8.3 name string
uint8_t SdFile::make83Name(const char* str, uint8_t* name) {
  uint8_t c;
  uint8_t n = 7;  // max index for part before dot
  uint8_t i = 0;
  // blank fill name and extension
  while (i < 11) name[i++] = ' ';
  i = 0;
  while ((c = *str++) != '\0') {
    if (c == '.') {
      if (n == 10) return false;  // only one dot allowed
      n = 10;  // max index for full 8.3 name
      i = 8;   // place for extension
    } else {
      // illegal FAT characters
      uint8_t b;                                              <<<<< this is line 261 <<<<<<<<<<<<
#if defined(__AVR__)
      PGM_P p = PSTR("|<>^+=?/[];,*\"\\");
      while ((b = pgm_read_byte(p++))) if (b == c) return false;
#elif defined(__arm__)
      const uint8_t valid[] = "|<>^+=?/[];,*\"\\";
      const uint8_t *p = valid;
      while ((b = *p++)) if (b == c) return false;
#endif
      // check size and only allow ASCII printable characters
      if (i > n || c < 0X21 || c > 0X7E)return false;
      // only upper case allowed in 8.3 names - convert lower to upper
      name[i++] = c < 'a' || c > 'z' ?  c : c + ('A' - 'a');
    }
  }
  // must have a file name, extension is optional
  return name[0] != ' ';
}

Note that if neither __AVR__ nor __arm__ are defined, variable b is unused.
I am unfamiliar with the possible values that should be checked here, but the definition of b could be inside the if defined statements to eliminate the warning.

But perhaps there should be another test?

I am compiling for an Arduino 101.
IDE 1.6.16
Mac OS X 10.11.6
SD Library 1.1.1


PaulS

Quote
But perhaps there should be another test?
No. There should be an else clause.

      uint8_t b;                                              <<<<< this is line 261 <<<<<<<<<<<<
#if defined(__AVR__)
      PGM_P p = PSTR("|<>^+=?/[];,*\"\\");
      while ((b = pgm_read_byte(p++))) if (b == c) return false;
#elif defined(__arm__)
      const uint8_t valid[] = "|<>^+=?/[];,*\"\\";
      const uint8_t *p = valid;
      while ((b = *p++)) if (b == c) return false;
#else
      b = b;

#endif
The art of getting good answers lies in asking good questions.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy