banner

[Rule] Rules  [Home] Main Forum  [Portal] Portal  
[Members] Member Listing  [Statistics] Statistics  [Search] Search  [Reading Room] Reading Room 
[Register] Register  
[Login] Loginhttp  | https  ]
 
Forum Index Thảo luận hệ điều hành *nix memcmp báo segmentation fault  XML
  [Question]   memcmp báo segmentation fault 29/01/2013 12:25:46 (+0700) | #1 | 273139
[Avatar]
suxanero
Member

[Minus]    0    [Plus]
Joined: 16/02/2007 15:37:29
Messages: 39
Offline
[Profile] [PM]
Code c for linux nhu sau: bị lỗi segmentation fault la o ham memcmp là sao mấy anh nhỉ?


Code:
#define HALM_BRIDGE_NAME_LEN 16

struct hsl_bridge
{

    char name[HALM_BRIDGE_NAME_LEN + 1];  
}

int hsl_vlan_add (char *name, hsl_vid_t vid)
{
	if (bridge && NULL!=name && NULL!=bridge->name)
	{

			if(memcmp(bridge->name, name, HALM_BRIDGE_NAME_LEN))
			{
				//do sometihng	
			}
	}
}



nó báo lỗi thế này, em chẳng hiểu tại sao mà lại lỗi
Code:
Segmentation fault
GPR00: dd5e3814 c1e67c50 b90e54a0 00000008 c391e34f 00000010 00000007 00000001 
GPR08: a031f960 00000000 0ab11b46 a0010e58 22000028 1043e59c 3ffef700 11ec3160 
GPR16: 11e863a0 00000004 100b4cb4 10336d88 00000002 00000008 c1e67ddc c1e67dfc 
GPR24: c1e67ddc c1e67dfc dd640000 00000001 c391e350 dd640000 bc4a3584 00000000 
NIP [a0010e6c] memcmp+0x14/0x30
LR [dd5e38b4] hsl_vlan_add+0xe0/0x1a0 [hsm]
Call Trace:
[c1e67c50] [dd5e3814] hsl_vlan_add+0x40/0x1a0 [hsm] (unreliable)
[c1e67c70] [dd5d878c] hsl_msg_recv_vlan_add+0x38/0xc8 [hsm]
[c1e67c90] [dd5d3b34] hsl_sock_process_msg+0x528/0x7f4 [hsm]
[c1e67ca0] [dd5d3e5c] _hsl_sock_sendmsg+0x5c/0x8c [hsm]
[c1e67cc0] [a01a8e64] sock_sendmsg+0xac/0xe4
[c1e67db0] [a01a9070] sys_sendmsg+0x1d4/0x284
[c1e67f00] [a01a9bd8] sys_socketcall+0xe8/0x200

Link hình báo lỗi : http://imageshack.us/photo/my-images/594/20128868.png/

[Up] [Print Copy]
  [Question]   memcmp báo segmentation fault 29/01/2013 12:32:09 (+0700) | #2 | 273140
[Avatar]
suxanero
Member

[Minus]    0    [Plus]
Joined: 16/02/2007 15:37:29
Messages: 39
Offline
[Profile] [PM]
PS : duplicate, xoá hộ em
[Up] [Print Copy]
  [Question]   memcmp báo segmentation fault 29/01/2013 13:29:07 (+0700) | #3 | 273143
[Avatar]
conmale
Administrator

Joined: 07/05/2004 23:43:15
Messages: 9353
Location: down under
Offline
[Profile] [PM]
Quan trọng là cái //do something có cái gì?
What bringing us together is stronger than what pulling us apart.
[Up] [Print Copy]
  [Question]   memcmp báo segmentation fault 29/01/2013 15:57:44 (+0700) | #4 | 273148
[Avatar]
suxanero
Member

[Minus]    0    [Plus]
Joined: 16/02/2007 15:37:29
Messages: 39
Offline
[Profile] [PM]
hi cảm ơn anh.

em tìm ra lỗi rồi ạ.

nguyên nhân lỗi rất cơ bản: bridge là 1 biến toàn cục, người ta không gián giá trị NULL sau khi giải phòng vùng nhớ dấn tới bridge vẫn trỏ tới 1 vùng nhớ không thuộc phạm vi của nó nữa.


[Up] [Print Copy]
[digg] [delicious] [google] [yahoo] [technorati] [reddit] [stumbleupon]
Go to: 
 Users currently in here 
1 Anonymous

Powered by JForum - Extended by HVAOnline
 hvaonline.net  |  hvaforum.net  |  hvazone.net  |  hvanews.net  |  vnhacker.org
1999 - 2013 © v2012|0504|218|