Skip to content

Commit 2a31bc4

Browse files
committed
Fix input string const-ness to avoid warnings with literal strings
1 parent 21e0f0e commit 2a31bc4

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

Diff for: cores/arduino/Stream.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,28 @@ void Stream::setTimeout(unsigned long timeout) // sets the maximum number of mi
9090
}
9191

9292
// find returns true if the target string is found
93-
bool Stream::find(char *target)
93+
bool Stream::find(const char *target)
9494
{
9595
return findUntil(target, strlen(target), NULL, 0);
9696
}
9797

9898
// reads data from the stream until the target string of given length is found
9999
// returns true if target string is found, false if timed out
100-
bool Stream::find(char *target, size_t length)
100+
bool Stream::find(const char *target, size_t length)
101101
{
102102
return findUntil(target, length, NULL, 0);
103103
}
104104

105105
// as find but search ends if the terminator string is found
106-
bool Stream::findUntil(char *target, char *terminator)
106+
bool Stream::findUntil(const char *target, const char *terminator)
107107
{
108108
return findUntil(target, strlen(target), terminator, strlen(terminator));
109109
}
110110

111111
// reads data from the stream until the target string of the given length is found
112112
// search terminated if the terminator string is found
113113
// returns true if target string is found, false if terminated or timed out
114-
bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen)
114+
bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
115115
{
116116
if (terminator == NULL) {
117117
MultiTarget t[1] = {{target, targetLen, 0}};

Diff for: cores/arduino/Stream.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,21 @@ class Stream : public Print
6868
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
6969
unsigned long getTimeout(void) { return _timeout; }
7070

71-
bool find(char *target); // reads data from the stream until the target string is found
72-
bool find(uint8_t *target) { return find ((char *)target); }
71+
bool find(const char *target); // reads data from the stream until the target string is found
72+
bool find(const uint8_t *target) { return find ((const char *)target); }
7373
// returns true if target string is found, false if timed out (see setTimeout)
7474

75-
bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
76-
bool find(uint8_t *target, size_t length) { return find ((char *)target, length); }
75+
bool find(const char *target, size_t length); // reads data from the stream until the target string of given length is found
76+
bool find(const uint8_t *target, size_t length) { return find ((const char *)target, length); }
7777
// returns true if target string is found, false if timed out
7878

7979
bool find(char target) { return find (&target, 1); }
8080

81-
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
82-
bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); }
81+
bool findUntil(const char *target, const char *terminator); // as find but search ends if the terminator string is found
82+
bool findUntil(const uint8_t *target, const char *terminator) { return findUntil((const char *)target, terminator); }
8383

84-
bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
85-
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); }
84+
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); // as above but search ends if the terminate string is found
85+
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) {return findUntil((const char *)target, targetLen, terminate, termLen); }
8686

8787
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
8888
// returns the first valid (long) integer value from the current position.

0 commit comments

Comments
 (0)