当前位置: 技术问答>linux和unix
函数调用参数传递的问题
来源: 互联网 发布时间:2016-06-03
本文导语: 也就是 guint8* output = NULL; output = (guint8*) g_malloc0 (0x20); 和 guint8 output[ 0x20 ]; 在下面代码中的不同 [code] int main() { guint8 input[] = {0x10, 0xf3, 0x07, 0xb7, 0x12, 0x4d, 0x06, 0x9b, 0x31, 0xc9, 0xf0, 0x00, 0x87, 0x43, 0x1a,...
也就是
guint8* output = NULL;
output = (guint8*) g_malloc0 (0x20);
和
guint8 output[ 0x20 ];
在下面代码中的不同
[code]
int main()
{
guint8 input[] = {0x10, 0xf3, 0x07, 0xb7, 0x12, 0x4d, 0x06, 0x9b, 0x31, 0xc9, 0xf0, 0x00, 0x87, 0x43,
0x1a, 0x67, 0xc0, 0x7f, 0x9e, 0x2c, 0x13, 0xb3, 0x90, 0x14, 0xd0, 0x91, 0xe4, 0x09, 0x5a, 0x6e, 0xdf, 0x21};
guint8 key[] = {0xd7, 0x87, 0x7e, 0xf4, 0x2e, 0x9e, 0x26, 0x77, 0x76, 0x94, 0x1e, 0x42, 0x3c, 0x0f, 0x81, 0xd6};
guint8* output = NULL;
output = g_malloc0( 0x20);
guint16 output_len = qq_decrypt(output, input, 0x20, key);
g_print ("OUTPUT_LEN = %dn",output_len);
}
运行失常
[/code]
[code]
int main()
{
guint8 input[] = {0x10, 0xf3, 0x07, 0xb7, 0x12, 0x4d, 0x06, 0x9b, 0x31, 0xc9, 0xf0, 0x00, 0x87, 0x43,
0x1a, 0x67, 0xc0, 0x7f, 0x9e, 0x2c, 0x13, 0xb3, 0x90, 0x14, 0xd0, 0x91, 0xe4, 0x09, 0x5a, 0x6e, 0xdf, 0x21};
guint8 key[] = {0xd7, 0x87, 0x7e, 0xf4, 0x2e, 0x9e, 0x26, 0x77, 0x76, 0x94, 0x1e, 0x42, 0x3c, 0x0f, 0x81, 0xd6};
guint8 output[sizeof (input)];
guint16 output_len = qq_decrypt(output, input, 0x20, key);
g_print ("OUTPUT_LEN = %dn",output_len);
}
运行正常
[/code]
qq_crypt 定义:
gint qq_decrypt(guint8 *plain, const guint8* const crypted, const gint crypted_len, const guint8* const key)
guint8* output = NULL;
output = (guint8*) g_malloc0 (0x20);
和
guint8 output[ 0x20 ];
在下面代码中的不同
[code]
int main()
{
guint8 input[] = {0x10, 0xf3, 0x07, 0xb7, 0x12, 0x4d, 0x06, 0x9b, 0x31, 0xc9, 0xf0, 0x00, 0x87, 0x43,
0x1a, 0x67, 0xc0, 0x7f, 0x9e, 0x2c, 0x13, 0xb3, 0x90, 0x14, 0xd0, 0x91, 0xe4, 0x09, 0x5a, 0x6e, 0xdf, 0x21};
guint8 key[] = {0xd7, 0x87, 0x7e, 0xf4, 0x2e, 0x9e, 0x26, 0x77, 0x76, 0x94, 0x1e, 0x42, 0x3c, 0x0f, 0x81, 0xd6};
guint8* output = NULL;
output = g_malloc0( 0x20);
guint16 output_len = qq_decrypt(output, input, 0x20, key);
g_print ("OUTPUT_LEN = %dn",output_len);
}
运行失常
[/code]
[code]
int main()
{
guint8 input[] = {0x10, 0xf3, 0x07, 0xb7, 0x12, 0x4d, 0x06, 0x9b, 0x31, 0xc9, 0xf0, 0x00, 0x87, 0x43,
0x1a, 0x67, 0xc0, 0x7f, 0x9e, 0x2c, 0x13, 0xb3, 0x90, 0x14, 0xd0, 0x91, 0xe4, 0x09, 0x5a, 0x6e, 0xdf, 0x21};
guint8 key[] = {0xd7, 0x87, 0x7e, 0xf4, 0x2e, 0x9e, 0x26, 0x77, 0x76, 0x94, 0x1e, 0x42, 0x3c, 0x0f, 0x81, 0xd6};
guint8 output[sizeof (input)];
guint16 output_len = qq_decrypt(output, input, 0x20, key);
g_print ("OUTPUT_LEN = %dn",output_len);
}
运行正常
[/code]
qq_crypt 定义:
gint qq_decrypt(guint8 *plain, const guint8* const crypted, const gint crypted_len, const guint8* const key)
|
output = g_malloc0( 0x20);
分配内存成功了吗? output 等于多少?
|
output[0x20] 不是已经越界了嘛
两个程序的区别就是:
第一个从堆里分配内存;第二个从栈里分配内存...