Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/srutils: fix gcc warning GH#612 #626

Merged
merged 1 commit into from May 18, 2016

Conversation

mslehto
Copy link
Member

@mslehto mslehto commented May 17, 2016

Attempt to fix #612

sha256.c: In function 'sr_SHA256_Final':
sha256.c:613:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
(sha2_word64)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount;
^
sha256.c: In function 'SHA512_Last':
sha256.c:930:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
(sha2_word64)&context->buffer[SHA512_SHORT_BLOCK_LENGTH] = context->bitcount[1];
^
sha256.c:931:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
(sha2_word64)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0];
^

> sha256.c: In function 'sr_SHA256_Final':
> sha256.c:613:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
>    *(sha2_word64*)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount;
>    ^
> sha256.c: In function 'SHA512_Last':
> sha256.c:930:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
>    *(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH] = context->bitcount[1];
>    ^
> sha256.c:931:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
>  *(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0];
>  ^
@mslehto
Copy link
Member Author

mslehto commented May 17, 2016

This little test program shows same output before and after patch.

#include <stdio.h>
#include "sha256.h"
#include "shautils.h"
#define BUFSIZE 1024

    int main(void) {

        uint8_t buffer[BUFSIZE];
        uint8_t src[2];

        src[0]='a';
        src[1]=0x0a;

        compute_sha256((char *)buffer, (uint8_t *)&src, sizeof(src));
        buffer[SHA256_DIGEST_STRING_LENGTH -1] = '\0';
        printf("%s\n", buffer);

        compute_sha512((char *)buffer, (uint8_t *)&src, sizeof(src));
        buffer[SHA512_DIGEST_STRING_LENGTH -1] = '\0';
        printf("%s\n", buffer);

        return 0;

    }

Output is also same when compared to /sbin/sha256 and /sbin/sha512 (FreeBSD 10).

% gcc -Wall shatest.c ../../md5.o sha256.o shautils.o

% ./a.out 
87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7
162b0b32f02482d5aca0a7c93dd03ceac3acd7e410a5f18f3fb990fc958ae0df6f32233b91831eaf99ca581a8c4ddf9c8ba315ac482db6d4ea01cc7884a635be
% echo a|sha256 ; echo a|sha512                                                                                                                 
87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7
162b0b32f02482d5aca0a7c93dd03ceac3acd7e410a5f18f3fb990fc958ae0df6f32233b91831eaf99ca581a8c4ddf9c8ba315ac482db6d4ea01cc7884a635be
%

@miconda
Copy link
Member

miconda commented May 18, 2016

Thanks!

@miconda miconda merged commit 5261d61 into kamailio:master May 18, 2016
@mslehto mslehto deleted the strict-aliasing branch May 21, 2016 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

compilation warnings
2 participants