Re: [go-nuts] cgo unusual errors/warnings

103 views
Skip to first unread message

Ian Lance Taylor

unread,
Apr 10, 2013, 9:33:35 PM4/10/13
to johnalan...@polylabs.ca, golan...@googlegroups.com
On Wed, Apr 10, 2013 at 6:01 PM, <johnalan...@polylabs.ca> wrote:
> I have the following C code embeded in my Go code
>
> int Base64Encode(const char* message, int length, char** buffer) { //Encodes
> a string to base64
> BIO *bio, *b64;
> //size_t size;
> FILE* stream;
> int encodedSize = 4*ceil((double)length/3);
> *buffer = (char *)malloc(encodedSize+1);
>
> stream = fmemopen(*buffer, encodedSize+1, "w");
> b64 = BIO_new(BIO_f_base64());
> bio = BIO_new_fp(stream, BIO_NOCLOSE);
> bio = BIO_push(b64, bio); //<--- LINE 35
> BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //Ignore newlines - write
> everything in one line
> BIO_write(bio, message, length);
> BIO_flush(bio);
> BIO_free_all(bio);
> fclose(stream);
>
> return (0); //success
> }
>
> when I run go run xxx.go, it returns with the error xxx.go:35 error: Value
> computed is not used [-Werror=unused-value]
> Basically it is saying I have computed some value on line 35 (marked in the
> code) assign it to the variable bio, and then not use it,
> However I use on the next 4 lines after that, so I am a little confused.
>
> Any help would be greatly appreciated

Probably BIO_push is a macro. Put your C code in a .c file and run
gcc -E to see what BIO_push expands to.

Ian

Maxim Khitrov

unread,
Apr 10, 2013, 9:50:09 PM4/10/13
to johnalan...@polylabs.ca, golan...@googlegroups.com
The line numbering is wrong. It's actually complaining about the line
"BIO_flush(bio);" which gets expanded to
"(int)BIO_ctrl(bio,11,0,((void *)0));".

Maxim Khitrov

unread,
Apr 11, 2013, 6:18:14 AM4/11/13
to johnalan...@polylabs.ca, golan...@googlegroups.com
I compiled your code as a regular c file and got the same warning.
Changing the line to "(void)BIO_flush(bio);" fixes it.

On Thu, Apr 11, 2013 at 12:54 AM, <johnalan...@polylabs.ca> wrote:
> What makes you think its pointing at the wrong line?
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Maxim Khitrov

unread,
Apr 11, 2013, 8:25:38 AM4/11/13
to johnalan...@polylabs.ca, golan...@googlegroups.com, Ian Lance Taylor
Hmm... Issue 4019 was supposed to fix line numbering, but it's still
not correct in tip. When using go 1.0.3 the line number is off by 2 in
my test, while in tip it's off by 1. New issue filed:

https://code.google.com/p/go/issues/detail?id=5272
Reply all
Reply to author
Forward
0 new messages