I have this code:
static char * display(const u8 array[], int length) {
int i;
char *str;
for (i = 0; i < length; i++) {
if (i%32 == 0) {
//printf("\n");
strcat(str, "\n");
}
if (i%8 == 0) {
//printf(" ");
strcat(str, " ");
}
//printf("%02X", array[i]);
strcat(str, (char *)array[i]);
}
return str;
/*
char str[80];
strcpy (str,"these ");
strcat (str,"strings ");
strcat (str,"are ");
strcat (str,"concatenated.");
puts (str);
return 0;
*/
}
Originally this code was printing a string. I dont want it to print a string, I need to make it returning a string. But it gives me this error:
main.c: In function 'display':
main.c:1707:9: warning: passing argument 2 of 'strcat' makes pointer from integer without a cast [ena bled by default]strcat(str, array[i]); ^ In file included from main.c:61:0:
/usr/include/string.h:133:14: note: expected 'const char * restrict' but argument is of type 'u8' extern char *strcat (char *__restrict __dest, const char *__restrict __src)
^ sh-4.2# gcc -o main *.c
main.c: In function 'display':
main.c:1707:21: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
strcat(str, (char *)array[i]);
EDIT:
build shared object and load:
VALUE generateIt(char *valor) {
struct NESSIEstruct w;
u8 digest[DIGESTBYTES];
int i;
for(i=0; valor[i]!='\0'; ++i);
int sizeo = i;
NESSIEinit(&w);
NESSIEadd((u8*)valor, 8*sizeo, &w);
NESSIEfinalize(&w, digest);
return displayIt(digest, DIGESTBYTES);
}
on top I do:
#include 'ruby.h'
and I add also this:
void
Init_whirlpool(){
rb_mWhirlpool = rb_define_module("Whirlpool");
rb_cClass = rb_define_class_under(rb_mWhirlpool, "Class", rb_cObject);
rb_define_method(rb_cClass, "generate", generateIt, 1);
}
u8
is obviously not the right type. – Ed S.str
is an uninitialized pointer that will have an undefined value. Probably going to crash when you use it. – crashmstrVALUE
is it a generic type used byruby
? something likevoid *
? I am almost sure the problem is you need to use some ruby custom memory allocation funciton that lets the interpreter handle memory allocation. And where did you add thefree
? – Iharob Al Asimi