mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 05:06:44 +00:00
Properly terminate buffer
This commit is contained in:
parent
a2a55ccdb8
commit
e021978294
@ -43,7 +43,7 @@ bool telnetInCommandMode = false;
|
|||||||
uint8_t telnetEnabled = true; // Enable telnet debug output
|
uint8_t telnetEnabled = true; // Enable telnet debug output
|
||||||
uint8_t telnetLoginAttempt = 0; // Initial attempt
|
uint8_t telnetLoginAttempt = 0; // Initial attempt
|
||||||
uint8_t telnetInputIndex = 0; // Empty buffer
|
uint8_t telnetInputIndex = 0; // Empty buffer
|
||||||
char telnetInputBuffer[128];
|
char telnetInputBuffer[128] = "";
|
||||||
|
|
||||||
void telnetClientDisconnect()
|
void telnetClientDisconnect()
|
||||||
{
|
{
|
||||||
@ -113,7 +113,7 @@ void telnetProcessCommand(char ch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void telnetProcessLine()
|
static inline void telnetProcessLine()
|
||||||
{
|
{
|
||||||
telnetInputBuffer[telnetInputIndex] = 0; // null terminate our char array
|
telnetInputBuffer[telnetInputIndex] = 0; // null terminate our char array
|
||||||
|
|
||||||
@ -159,17 +159,17 @@ static void telnetProcessLine()
|
|||||||
telnetInputIndex = 0; // reset input buffer index
|
telnetInputIndex = 0; // reset input buffer index
|
||||||
}
|
}
|
||||||
|
|
||||||
static void telnetProcessData(char ch)
|
static inline void telnetProcessData(char ch)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case 10:
|
case 10: // Linefeed
|
||||||
telnetInputIndex = 0;
|
telnetInputIndex = 0;
|
||||||
break;
|
break;
|
||||||
case 8: // Backspace
|
case 8: // Backspace
|
||||||
if(telnetInputIndex > 0) telnetInputIndex--;
|
if(telnetInputIndex > 0) telnetInputIndex--;
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13: // Cariage Return
|
||||||
telnetProcessLine();
|
telnetProcessLine();
|
||||||
break;
|
break;
|
||||||
case 32 ... 250:
|
case 32 ... 250:
|
||||||
@ -179,9 +179,13 @@ static void telnetProcessData(char ch)
|
|||||||
// If we have room left in our buffer add the current byte
|
// If we have room left in our buffer add the current byte
|
||||||
if(telnetInputIndex < sizeof(telnetInputBuffer) - 1) {
|
if(telnetInputIndex < sizeof(telnetInputBuffer) - 1) {
|
||||||
telnetInputBuffer[telnetInputIndex++] = ch;
|
telnetInputBuffer[telnetInputIndex++] = ch;
|
||||||
// telnetInputIndex++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Properly terminate buffer string
|
||||||
|
if(telnetInputIndex < sizeof(telnetInputBuffer)) {
|
||||||
|
telnetInputBuffer[telnetInputIndex] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void telnetProcessCharacter(char ch)
|
static inline void telnetProcessCharacter(char ch)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user