[AGENT++] It works

qqbao qqbao at fiberhome.com.cn
Wed Nov 23 07:26:26 CET 2011


> the pointer size should not matter, but if int is 32 bit I can only
> think of an unaligned access. So I suggest the following (untested):

> unsigned int IpAddress::get_scope() const
> {
>   ADDRESS_TRACE;
>   if (!valid_flag)
>     return (unsigned int)-1; // don't use uninitialized memory

>   if ((ip_version != version_ipv6) || (!have_ipv6_scope))
>     return (unsigned int)-1;

>  unsigned int scope;
>  memcpy(&scope, address_buffer + IP6LEN_NO_SCOPE, 4);
>  return ntohl(scope);
> }

> bool IpAddress::set_scope(const unsigned int scope)
> {
>   ADDRESS_TRACE;
>   if (!valid_flag || (ip_version != version_ipv6))
>       return false;
>   unsigned int scope_network = htonl(scope);
>   memcpy(address_buffer + IP6LEN_NO_SCOPE, &scope_network, 4);
>   addr_changed = true;
>   smival.value.string.len = IP6LEN_WITH_SCOPE;
>   have_ipv6_scope = true;
>   return true;
> }

 
Thanks for your suggest. It works.
It's really caused by an unaligned access.

Also, I found that the crash was caused by the following:

class DLLOPT Address : public SnmpSyntax
{
...
protected:
 SNMP_PP_MUTABLE bool addr_changed; 
 bool valid_flag;
 unsigned char address_buffer[ADDRBUF];   
...
};
            
Fixed it as follows: 
  
class DLLOPT Address : public SnmpSyntax
{
...
protected:
unsigned char address_buffer[ADDRBUF]; // define this first
SNMP_PP_MUTABLE bool addr_changed; 
bool valid_flag;
...
};

It also works.

2011-11-23 



qqbao 



More information about the AGENTPP mailing list