
< 		gsm->buf[gsm->count++] = c;
< 		if (gsm->count == gsm->len)
---
> 		if (gsm->count < sizeof(gsm->buf)) {
> 			gsm->buf[gsm->count++] = c;
> 			if (gsm->count == gsm->len)
> 		} else {
> 			gsm->state = GSM_RECOVERY;  // Or appropriate error handling
> 		}
