Skip to content

Commit

Permalink
CMakefile: add -Wstrict-aliasing=2 and fix warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Kirill A. Shutemov <[email protected]>
  • Loading branch information
kiryl committed Aug 30, 2011
1 parent 2fcf9c8 commit 0b2c406
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ IF (MSVC)
SET(CMAKE_C_FLAGS_DEBUG "/Od /DEBUG /MTd")
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
ELSE ()
SET(CMAKE_C_FLAGS "-O2 -g -Wall -Wextra")
SET(CMAKE_C_FLAGS "-O2 -g -Wall -Wextra -Wstrict-aliasing=2")
IF (NOT MINGW) # MinGW always does PIC and complains if we tell it to
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
ENDIF ()
Expand Down
12 changes: 6 additions & 6 deletions src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ void git_cache_free(git_cache *cache)

void *git_cache_get(git_cache *cache, const git_oid *oid)
{
const uint32_t *hash;
uint32_t hash;
cache_node *node = NULL;
void *result = NULL;

hash = (const uint32_t *)oid->id;
node = &cache->nodes[hash[0] & cache->size_mask];
memcpy(&hash, oid->id, sizeof(hash));
node = &cache->nodes[hash & cache->size_mask];

git_mutex_lock(&node->lock);
{
Expand All @@ -97,13 +97,13 @@ void *git_cache_get(git_cache *cache, const git_oid *oid)

void *git_cache_try_store(git_cache *cache, void *entry)
{
const uint32_t *hash;
uint32_t hash;
const git_oid *oid;
cache_node *node = NULL;

oid = &((git_cached_obj*)entry)->oid;
hash = (const uint32_t *)oid->id;
node = &cache->nodes[hash[0] & cache->size_mask];
memcpy(&hash, oid->id, sizeof(hash));
node = &cache->nodes[hash & cache->size_mask];

/* increase the refcount on this object, because
* the cache now owns it */
Expand Down
5 changes: 4 additions & 1 deletion src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buf

while (buffer < buffer_end) {
git_tree_entry *entry;
long tmp;

entry = git__calloc(1, sizeof(git_tree_entry));
if (entry == NULL) {
Expand All @@ -185,8 +186,10 @@ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buf
if (git_vector_insert(&tree->entries, entry) < GIT_SUCCESS)
return GIT_ENOMEM;

if (git__strtol32((long *)&entry->attr, buffer, &buffer, 8) < GIT_SUCCESS)
if (git__strtol32(&tmp, buffer, &buffer, 8) < GIT_SUCCESS ||
!buffer || tmp > UINT_MAX || tmp < 0)
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Can't parse attributes");
entry->attr = tmp;

if (*buffer++ != ' ') {
error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Object it corrupted");
Expand Down

0 comments on commit 0b2c406

Please sign in to comment.