mirror of
https://github.com/git/git.git
synced 2024-11-27 20:14:30 +08:00
952fba9c63
Change direct and indirect assignments of the bitwise negation of 0 to uint32_t variables to have a "U" suffix. I.e. ~0U instead of ~0. This eliminates warnings under Sun Studio 12 Update 1: "vcs-svn/string_pool.c", line 11: warning: initializer will be sign-extended: -1 (E_INIT_SIGN_EXTEND) "vcs-svn/string_pool.c", line 81: warning: initializer will be sign-extended: -1 (E_INIT_SIGN_EXTEND) "vcs-svn/repo_tree.c", line 112: warning: initializer will be sign-extended: -1 (E_INIT_SIGN_EXTEND) "vcs-svn/repo_tree.c", line 112: warning: initializer will be sign-extended: -1 (E_INIT_SIGN_EXTEND) "test-treap.c", line 34: warning: initializer will be sign-extended: -1 (E_INIT_SIGN_EXTEND) The semantics are still the same as demonstrated by this program: $ cat test.c && make test && ./test #include <stdio.h> #include <stdint.h> int main(void) { uint32_t foo = ~0; uint32_t bar = ~0U; printf("foo = <%u> bar = <%u>\n", foo, bar); return 0; } cc test.c -o test "test.c", line 5: warning: initializer will be sign-extended: -1 foo = <4294967295> bar = <4294967295> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
71 lines
1.7 KiB
C
71 lines
1.7 KiB
C
/*
|
|
* test-treap.c: code to exercise the svn importer's treap structure
|
|
*/
|
|
|
|
#include "cache.h"
|
|
#include "vcs-svn/obj_pool.h"
|
|
#include "vcs-svn/trp.h"
|
|
|
|
struct int_node {
|
|
uintmax_t n;
|
|
struct trp_node children;
|
|
};
|
|
|
|
obj_pool_gen(node, struct int_node, 3)
|
|
|
|
static int node_cmp(struct int_node *a, struct int_node *b)
|
|
{
|
|
return (a->n > b->n) - (a->n < b->n);
|
|
}
|
|
|
|
trp_gen(static, treap_, struct int_node, children, node, node_cmp)
|
|
|
|
static void strtonode(struct int_node *item, const char *s)
|
|
{
|
|
char *end;
|
|
item->n = strtoumax(s, &end, 10);
|
|
if (*s == '\0' || (*end != '\n' && *end != '\0'))
|
|
die("invalid integer: %s", s);
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
struct strbuf sb = STRBUF_INIT;
|
|
struct trp_root root = { ~0U };
|
|
uint32_t item;
|
|
|
|
if (argc != 1)
|
|
usage("test-treap < ints");
|
|
|
|
while (strbuf_getline(&sb, stdin, '\n') != EOF) {
|
|
struct int_node *node = node_pointer(node_alloc(1));
|
|
|
|
item = node_offset(node);
|
|
strtonode(node, sb.buf);
|
|
node = treap_insert(&root, node_pointer(item));
|
|
if (node_offset(node) != item)
|
|
die("inserted %"PRIu32" in place of %"PRIu32"",
|
|
node_offset(node), item);
|
|
}
|
|
|
|
item = node_offset(treap_first(&root));
|
|
while (~item) {
|
|
uint32_t next;
|
|
struct int_node *tmp = node_pointer(node_alloc(1));
|
|
|
|
tmp->n = node_pointer(item)->n;
|
|
next = node_offset(treap_next(&root, node_pointer(item)));
|
|
|
|
treap_remove(&root, node_pointer(item));
|
|
item = node_offset(treap_nsearch(&root, tmp));
|
|
|
|
if (item != next && (!~item || node_pointer(item)->n != tmp->n))
|
|
die("found %"PRIuMAX" in place of %"PRIuMAX"",
|
|
~item ? node_pointer(item)->n : ~(uintmax_t) 0,
|
|
~next ? node_pointer(next)->n : ~(uintmax_t) 0);
|
|
printf("%"PRIuMAX"\n", tmp->n);
|
|
}
|
|
node_reset();
|
|
return 0;
|
|
}
|