]> granicus.if.org Git - graphviz/commitdiff
cgraph: squash some -Wconversion warnings
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Nov 2022 17:44:36 +0000 (09:44 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Nov 2022 22:51:26 +0000 (14:51 -0800)
This squashes the following warnings on CentOS 7 where the compiler believes
the sequence ID may overflow:

  node.c: In function 'agnodebefore':
  node.c:370:23: warning: conversion to 'unsigned int:28' from 'int' may alter
    its value [-Wconversion]
     AGSEQ(n) = AGSEQ(n) + 1;
                         ^
  node.c:376:26: warning: conversion to 'unsigned int:28' from 'int' may alter
    its value [-Wconversion]
    AGSEQ(snd) = AGSEQ(fst) - 1;
                            ^

lib/cgraph/node.c

index f72970e214d2bf42cdff481f01aa3b87e422bf74..f6ca59bb012366430315700232c5b8bd3dde25af 100644 (file)
@@ -367,13 +367,16 @@ int agnodebefore(Agnode_t *fst, Agnode_t *snd)
        do {
                nxt = agprvnode(g,n);
                if (agapply (g, (Agobj_t *) n, (agobjfn_t) agnodesetfinger, n, FALSE) != SUCCESS) return FAILURE;
-               AGSEQ(n) = AGSEQ(n) + 1;
+               uint64_t seq = AGSEQ(n) + 1;
+               assert((seq & SEQ_MASK) == seq && "sequence ID overflow");
+               AGSEQ(n) = seq & SEQ_MASK;
                if (agapply (g, (Agobj_t *) n, (agobjfn_t) agnoderenew, n, FALSE) != SUCCESS) return FAILURE;
                if (n == fst) break;
                n = nxt;
        } while (n);
        if (agapply (g, (Agobj_t *) snd, (agobjfn_t) agnodesetfinger, n, FALSE) != SUCCESS) return FAILURE;
-       AGSEQ(snd) = AGSEQ(fst) - 1;
+       assert(AGSEQ(fst) != 0 && "sequence ID overflow");
+       AGSEQ(snd) = (AGSEQ(fst) - 1) & SEQ_MASK;
        if (agapply (g, (Agobj_t *) snd, (agobjfn_t) agnoderenew, snd, FALSE) != SUCCESS) return FAILURE;
        return SUCCESS;
 }