[3.4-dev] Obscure bug with queues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PowerWyrm
    Prophet
    • Apr 2008
    • 2986

    [3.4-dev] Obscure bug with queues

    I didn't check all the calls to "struct queue" in the code, but the ones in generate.c and obj-util.c assume that the queue can handle "size" pointers when created with a size of "size".

    When looking at the code in z-queue.c, pushing "size" items in a queue of size "size" will not work:

    Code:
    void q_push(struct queue *q, uintptr_t item) {
        q->data[q->tail] = item;
        q->tail = (q->tail + 1) % q->size;
        if (q->tail == q->head) abort();
    }
    For the last item, abort() will be called (which is quite ugly in itself -- it won't save the character state before quitting for example).

    Fix: either allow one more item in the queue, or add +1 to queue size when calling q_new().
    PWMAngband variant maintainer - check https://github.com/draconisPW/PWMAngband (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant!
  • d_m
    Angband Devteam member
    • Aug 2008
    • 1517

    #2
    Originally posted by PowerWyrm
    For the last item, abort() will be called (which is quite ugly in itself -- it won't save the character state before quitting for example).

    Fix: either allow one more item in the queue, or add +1 to queue size when calling q_new().
    Ooh, good catch!

    Yeah, it probably should call something else instead. I will fix this and also try to do something a bit more friendly.
    linux->xterm->screen->pmacs

    Comment

    • d_m
      Angband Devteam member
      • Aug 2008
      • 1517

      #3
      OK, this is fixed in angband/master and v4/v4-master.

      I chose to use (size + 1) in q_new so that if the user wants a queue of size 40 it allocates 41 buckets.

      Thanks again for catching this!
      linux->xterm->screen->pmacs

      Comment

      Working...
      😀
      😂
      🥰
      😘
      🤢
      😎
      😞
      😡
      👍
      👎