Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // KONSTRUKTOR
- SBuff::SBuff(uint16_t const size)
- {
- buffer = (char*)malloc(size + 1);
- if (buffer != NULL) // SUCCESS
- {
- allocFail = false;
- buffAlloc = size;
- memset(buffer, '\0', size + 1);
- }
- buffIdx = 0;
- }
- // FUNKCIJA ZA BUFFANJE
- void SBuff::buff(uint8_t const incomingByte, void (*func)())
- {
- if (!allocFail)
- {
- switch (incomingByte)
- {
- case '\n':
- {
- *(buffer + buffIdx) = '\0';
- func();
- dump();
- break;
- }
- case '\r': break;
- default: // OVDJE JE PROBLEM
- {
- //if (buffIdx < (buffAlloc - 1)) buffer[buffIdx++] = incomingByte; // OVERFLOW PROTECTION
- if (buffIdx < (buffAlloc - 1)) *(buffer + buffIdx++) = incomingByte; // OVERFLOW PROTECTION
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement