mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 09:25:44 +01:00
fix: no error return with procbuff.
This commit is contained in:
@@ -14,8 +14,7 @@
|
|||||||
#include "atrb.h"
|
#include "atrb.h"
|
||||||
|
|
||||||
int conf_procbuf(char const* restrict buf, char* restrict kout, char* restrict vout, size_t len) {
|
int conf_procbuf(char const* restrict buf, char* restrict kout, char* restrict vout, size_t len) {
|
||||||
// length data storage
|
bool feq = false; // whether we've found the equal sign
|
||||||
unsigned idx = 0; // index to the data below
|
|
||||||
|
|
||||||
// data traversal
|
// data traversal
|
||||||
char* pos = kout; // will point to the next point in the buffer, where we'll write data
|
char* pos = kout; // will point to the next point in the buffer, where we'll write data
|
||||||
@@ -35,20 +34,24 @@ int conf_procbuf(char const* restrict buf, char* restrict kout, char* restrict v
|
|||||||
if (brk) break;
|
if (brk) break;
|
||||||
|
|
||||||
// everything after `=` is interpreted as a value
|
// everything after `=` is interpreted as a value
|
||||||
if (buf[i] == '=' && !idx) {
|
if (!feq && buf[i] == '=') {
|
||||||
|
feq = true;
|
||||||
*pos = '\0'; // terminate string
|
*pos = '\0'; // terminate string
|
||||||
pos = vout; // move pointer to start of value data
|
pos = vout; // move pointer to start of value data
|
||||||
idx++;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*pos = buf[i]; // copy over the buffer's data
|
*pos = buf[i]; // copy over the buffer's data
|
||||||
pos++; // increment the position pointer
|
pos++; // increment the position pointer
|
||||||
}
|
}
|
||||||
if (pos == kout) return 0; // line was ignored if pos didn't move
|
|
||||||
|
|
||||||
// null-terminate what we've got now (yes, there should be enough space for this since \0 isn't stored)
|
// null-terminate what we've got now (yes, there should be enough space for this since \0 isn't stored)
|
||||||
|
// this also ensures the value is valid, even if none is given
|
||||||
*pos = '\0';
|
*pos = '\0';
|
||||||
return 0;
|
|
||||||
|
// no data if we didn't move from the key position
|
||||||
|
// syntax error if we couldn't find the equal sign
|
||||||
|
return (pos == kout)
|
||||||
|
? CONF_ENODAT
|
||||||
|
: (!feq ? CONF_ESYNTAX : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct conf_entry const* conf_matchopt(struct conf_entry const* opts, size_t optc, char const* restrict key) {
|
struct conf_entry const* conf_matchopt(struct conf_entry const* opts, size_t optc, char const* restrict key) {
|
||||||
|
|||||||
Reference in New Issue
Block a user