mirror of
https://github.com/git-for-windows/git.git
synced 2026-04-09 15:01:59 -05:00
pkt-line: make packet_reader.line non-const
The "line" member of a packet_reader struct is marked as const. This kind of makes sense, because it's not its own allocated buffer that should be freed, and we often use const to indicate that. But it is always writable, because it points into the non-const "buffer" member. And we rely on this writability in places like send-pack and receive-pack, where we parse incoming packet contents by writing NULs over delimiters. This has traditionally worked because we implicitly cast away the constness with strchr() like: const char *head; char *p; head = reader->line; p = strchr(head, ' '); Since C23 libc provides a generic strchr() to detect this implicit const removal, this now generate a compiler warning on some platforms (like recent glibc). We can fix it by marking "line" as non-const, as well as a few intermediate variables (like "head" in the above example). Note that by itself, switching to a non-const variable would cause problems with this line in send-pack.c: if (!skip_prefix(reader->line, "unpack ", &reader->line)) But due to our skip_prefix() magic introduced in the previous commit, this compiles fine (both the in and out-parameters are non-const, so we know it is safe). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
cefb8b7b47
commit
d3cd819e8b
@@ -1025,8 +1025,8 @@ static int read_proc_receive_report(struct packet_reader *reader,
|
||||
|
||||
for (;;) {
|
||||
struct object_id old_oid, new_oid;
|
||||
const char *head;
|
||||
const char *refname;
|
||||
char *head;
|
||||
char *refname;
|
||||
char *p;
|
||||
enum packet_read_status status;
|
||||
|
||||
@@ -1050,7 +1050,8 @@ static int read_proc_receive_report(struct packet_reader *reader,
|
||||
}
|
||||
*p++ = '\0';
|
||||
if (!strcmp(head, "option")) {
|
||||
const char *key, *val;
|
||||
char *key;
|
||||
const char *val;
|
||||
|
||||
if (!hint || !(report || new_report)) {
|
||||
if (!once++)
|
||||
|
||||
@@ -184,7 +184,7 @@ struct packet_reader {
|
||||
int pktlen;
|
||||
|
||||
/* the last line read */
|
||||
const char *line;
|
||||
char *line;
|
||||
|
||||
/* indicates if a line has been peeked */
|
||||
int line_peeked;
|
||||
|
||||
@@ -175,8 +175,8 @@ static int receive_status(struct repository *r,
|
||||
ret = receive_unpack_status(reader);
|
||||
while (1) {
|
||||
struct object_id old_oid, new_oid;
|
||||
const char *head;
|
||||
const char *refname;
|
||||
char *head;
|
||||
char *refname;
|
||||
char *p;
|
||||
if (packet_reader_read(reader) != PACKET_READ_NORMAL)
|
||||
break;
|
||||
@@ -190,7 +190,8 @@ static int receive_status(struct repository *r,
|
||||
*p++ = '\0';
|
||||
|
||||
if (!strcmp(head, "option")) {
|
||||
const char *key, *val;
|
||||
char *key;
|
||||
const char *val;
|
||||
|
||||
if (!hint || !(report || new_report)) {
|
||||
if (!once++)
|
||||
|
||||
Reference in New Issue
Block a user