]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
cbuf: improve some warns, minor cleanup
authorbones_was_here <bones_was_here@xonotic.au>
Fri, 15 Dec 2023 22:36:22 +0000 (08:36 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Thu, 21 Dec 2023 11:43:44 +0000 (21:43 +1000)
Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
cmd.c

diff --git a/cmd.c b/cmd.c
index 125488bfd74184259377a95397590ef031e91312..0343dd10582c83393f448d21a1a4827f38ccffc3 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -266,16 +266,18 @@ void Cbuf_AddText (cmd_state_t *cmd, const char *text)
        cmd_buf_t *cbuf = cmd->cbuf;
        llist_t llist = {&llist, &llist};
 
-       Cbuf_Lock(cbuf);
-
-       if (cbuf->maxsize - cbuf->size <= l)
-               Con_Print(CON_WARN "Cbuf_AddText: overflow\n");
-       else
+       if (cbuf->size + l > cbuf->maxsize)
        {
-               // If the string terminates but the (last) line doesn't, the node will be left in the pending state (to be continued).
-               Cbuf_ParseText(cmd, &llist, (List_Is_Empty(&cbuf->start) ? NULL : List_Entry(cbuf->start.prev, cmd_input_t, list)), text, true);
-               List_Splice_Tail(&llist, &cbuf->start);
+               Con_Printf(CON_WARN "Cbuf_AddText: input too large, %zuKB ought to be enough for anybody.\n", cbuf->maxsize / 1024);
+               return;
        }
+
+       Cbuf_Lock(cbuf);
+
+       // If the string terminates but the (last) line doesn't, the node will be left in the pending state (to be continued).
+       Cbuf_ParseText(cmd, &llist, (List_Is_Empty(&cbuf->start) ? NULL : List_Entry(cbuf->start.prev, cmd_input_t, list)), text, true);
+       List_Splice_Tail(&llist, &cbuf->start);
+
        Cbuf_Unlock(cbuf);
 }
 
@@ -292,19 +294,20 @@ void Cbuf_InsertText (cmd_state_t *cmd, const char *text)
        llist_t llist = {&llist, &llist};
        size_t l = strlen(text);
 
-       Cbuf_Lock(cbuf);
-
-       if (cbuf->size + l >= cbuf->maxsize)
-               Con_Print(CON_WARN "Cbuf_InsertText: overflow\n");
-       else
+       if (cbuf->size + l > cbuf->maxsize)
        {
-               // bones_was_here assertion: when prepending to the buffer it never makes sense to leave node(s) in the `pending` state,
-               // it would have been impossible to append to such text later in the old raw text buffer,
-               // and allowing it causes bugs when .cfg files lack \n at EOF (see: https://gitlab.com/xonotic/darkplaces/-/issues/378).
-               Cbuf_ParseText(cmd, &llist, (List_Is_Empty(&cbuf->start) ? NULL : List_Entry(cbuf->start.next, cmd_input_t, list)), text, false);
-               List_Splice(&llist, &cbuf->start);
+               Con_Printf(CON_WARN "Cbuf_InsertText: input too large, %zuKB ought to be enough for anybody.\n", cbuf->maxsize / 1024);
+               return;
        }
 
+       Cbuf_Lock(cbuf);
+
+       // bones_was_here assertion: when prepending to the buffer it never makes sense to leave node(s) in the `pending` state,
+       // it would have been impossible to append to such text later in the old raw text buffer,
+       // and allowing it causes bugs when .cfg files lack \n at EOF (see: https://gitlab.com/xonotic/darkplaces/-/issues/378).
+       Cbuf_ParseText(cmd, &llist, (List_Is_Empty(&cbuf->start) ? NULL : List_Entry(cbuf->start.next, cmd_input_t, list)), text, false);
+       List_Splice(&llist, &cbuf->start);
+
        Cbuf_Unlock(cbuf);
 }
 
@@ -321,7 +324,7 @@ static void Cbuf_Execute_Deferred (cmd_buf_t *cbuf)
        if (host.realtime - cbuf->deferred_oldtime < 0 || host.realtime - cbuf->deferred_oldtime > 1800)
                cbuf->deferred_oldtime = host.realtime;
        eat = host.realtime - cbuf->deferred_oldtime;
-       if (eat < 1/128)
+       if (eat < 1.0/128.0)
                return;
        cbuf->deferred_oldtime = host.realtime;