Преглед изворни кода

Never return NULL from String c_str() on Teensy 3.x

main
PaulStoffregen пре 4 година
родитељ
комит
2cd86801ae
2 измењених фајлова са 7 додато и 1 уклоњено
  1. +2
    -0
      teensy3/WString.cpp
  2. +5
    -1
      teensy3/WString.h

+ 2
- 0
teensy3/WString.cpp Прегледај датотеку

/* Character Access */ /* Character Access */
/*********************************************/ /*********************************************/


const char String::zerotermination = 0;

char String::charAt(unsigned int loc) const char String::charAt(unsigned int loc) const
{ {
return operator[](loc); return operator[](loc);

+ 5
- 1
teensy3/WString.h Прегледај датотеку

void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const;
void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
{getBytes((unsigned char *)buf, bufsize, index);} {getBytes((unsigned char *)buf, bufsize, index);}
const char * c_str() const { return buffer; }
const char * c_str() const {
if (!buffer) return &zerotermination; // https://forum.pjrc.com/threads/63842
return buffer;
}


// search // search
int indexOf( char ch ) const; int indexOf( char ch ) const;
// for more information http://www.artima.com/cppsource/safebool.html // for more information http://www.artima.com/cppsource/safebool.html
typedef void (String::*StringIfHelperType)() const; typedef void (String::*StringIfHelperType)() const;
void StringIfHelper() const {} void StringIfHelper() const {}
static const char zerotermination;
public: public:
operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; }
}; };

Loading…
Откажи
Сачувај