Skip to content

Commit dac98cc

Browse files
committed
Refactor csum verification
1 parent 67bceac commit dac98cc

1 file changed

Lines changed: 7 additions & 18 deletions

File tree

src/gdbstub.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -526,17 +526,12 @@ static void process_general_set(gdbstub_t *gdbstub, char *payload)
526526
#endif
527527

528528
if (!strcmp(name, "StartNoAckMode")) {
529-
/* Per GDB RSP: reply OK with acking still on, then disable after.
530-
* Since conn_send_pktstr is synchronous, we can set the flag
531-
* immediately after sending - the next packet won't ACK.
532-
*/
533-
conn_send_pktstr(&gdbstub->priv->conn, "OK");
534529
gdbstub->priv->conn.no_ack_mode = true;
530+
conn_send_pktstr(&gdbstub->priv->conn, "OK");
535531
#ifdef DEBUG
536532
printf("No-ack mode enabled\n");
537533
#endif
538534
} else {
539-
/* Unknown Q packet - send empty response */
540535
conn_send_pktstr(&gdbstub->priv->conn, "");
541536
}
542537
}
@@ -871,31 +866,25 @@ bool gdbstub_run(gdbstub_t *gdbstub, void *args)
871866
}
872867

873868
/* Verify checksum before processing */
874-
if (!packet_csum_verify(pkt)) {
875-
if (!conn->no_ack_mode) {
876-
/* In ack mode: send NACK to request retransmission */
877-
conn_send_str(conn, STR_NACK);
878-
}
879-
/* In no-ack mode: verify but don't send +/- */
869+
bool csum_ok = packet_csum_verify(pkt);
870+
if (!conn->no_ack_mode)
871+
conn_send_str(conn, csum_ok ? STR_ACK : STR_NACK);
872+
873+
if (!csum_ok) {
874+
free(pkt);
880875

881876
conn->failure_count++;
882877
if (conn->failure_count >= CONN_MAX_FAILURES) {
883878
warn("Too many consecutive failures (%d), disconnecting\n",
884879
conn->failure_count);
885-
free(pkt);
886880
return false;
887881
}
888-
free(pkt);
889882
continue; /* Discard packet and wait for retransmission */
890883
}
891884

892885
/* Checksum OK - reset failure counter */
893886
conn->failure_count = 0;
894887

895-
/* Send ACK only in ack mode */
896-
if (!conn->no_ack_mode)
897-
conn_send_str(conn, STR_ACK);
898-
899888
#ifdef DEBUG
900889
printf("packet = %s\n", pkt->data);
901890
#endif

0 commit comments

Comments
 (0)