Skip to content

Commit 952fba9

Browse files
avargitster
authored andcommitted
Fix a bitwise negation assignment issue spotted by Sun Studio
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d7a10c3 commit 952fba9

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

test-treap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static void strtonode(struct int_node *item, const char *s)
3131
int main(int argc, char *argv[])
3232
{
3333
struct strbuf sb = STRBUF_INIT;
34-
struct trp_root root = { ~0 };
34+
struct trp_root root = { ~0U };
3535
uint32_t item;
3636

3737
if (argc != 1)

vcs-svn/repo_tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static struct repo_dirent *repo_read_dirent(uint32_t revision,
109109
static void repo_write_dirent(const uint32_t *path, uint32_t mode,
110110
uint32_t content_offset, uint32_t del)
111111
{
112-
uint32_t name, revision, dir_o = ~0, parent_dir_o = ~0;
112+
uint32_t name, revision, dir_o = ~0U, parent_dir_o = ~0U;
113113
struct repo_dir *dir;
114114
struct repo_dirent *key;
115115
struct repo_dirent *dent = NULL;

vcs-svn/string_pool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "obj_pool.h"
99
#include "string_pool.h"
1010

11-
static struct trp_root tree = { ~0 };
11+
static struct trp_root tree = { ~0U };
1212

1313
struct node {
1414
uint32_t offset;
@@ -78,7 +78,7 @@ void pool_print_seq(uint32_t len, uint32_t *seq, char delim, FILE *stream)
7878
uint32_t pool_tok_seq(uint32_t sz, uint32_t *seq, const char *delim, char *str)
7979
{
8080
char *context = NULL;
81-
uint32_t token = ~0;
81+
uint32_t token = ~0U;
8282
uint32_t length;
8383

8484
if (sz == 0)

0 commit comments

Comments
 (0)