On 11/08/2016 12:17 PM, Robert Story wrote:
> On Tue, 8 Nov 2016 16:35:46 +0000 Moreno wrote:
> MF> As requested in the sujbect, what's the purpose of line 2824 in mib.c 
> file?
> MF>
> MF> tmpbuf2[strlen(tmpbuf2)-1] = 0;
> MF>
> MF> It causes my "/mibs" directory to be trimmed to "/mib" and nothing works.
>
> Then it sounds like your mibindex file is not well formed. It should start
> with a DIR line, followed by a line for each mib. e.g.
>
> --- start ---
> DIR /usr/share/snmp/mibs
> AGENTX-MIB AGENTX-MIB.txt
> --- end ---
>
> The first line is read by fgets():
>
>        fgets()  reads in at most one less than size characters from stream and
>        stores them into the buffer pointed to by s.  Reading  stops  after  an
>        EOF  or a newline.  If a newline is read, it is stored into the buffer.
>
> So the strlen - 1 chops off the newline.
>
> MF> Also, I had to memset to 0 all the buffers for peace of mind because
> MF> I'm porting netsnmp to an embedded plaform that doesn't automatically
> MF> set to zero static variables and arrays on declaration.
>
> Static buffers/arrays should be initialized before use. If you find any that
> are used before they are initialized, please file a bug and, if you can,
> submit a patch to fix them.

Hello Robert,

A quote from the C language standard (ISO/IEC 9899:201x): "6.9.2 
External object definitions. Semantics. If the declaration of an 
identifier for an object has file scope and an initializer, the
declaration is an external definition for the identifier. A declaration 
of an identifier for an object that has file scope without an 
initializer, and without a storage-class specifier or with the 
storage-class specifier static, constitutes a tentative definition. If a 
translation unit contains one or more tentative definitions for an 
identifier, and the translation unit contains no external definition for 
that identifier, then the behavior is exactly as if the translation unit 
contains a file scope declaration of that identifier, with the composite 
type as of the end of the translation unit, with an initializer equal to 0."

In other words, any toolchain that does not zero-initialize static 
variables violates the C standard. I don't think we should care about 
broken toolchains.

Bart.

------------------------------------------------------------------------------
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to