On Wed, 2012-09-05 at 10:46 +0530, Jatin Bodarya wrote:
> Below is my code which is showing warning of 
> 
> ionline.c: In function 'handle_memory':
> > ionline.c: warning: ignoring return value of 'system', declared 
> > with attribute warn_unused_result [-Wunused-result]
> > ionline.c: warning: ignoring return value of 'fscanf', declared 
> > with attribute warn_unused_result [-Wunused-result]
> 
> Why it it not talking any function which is returning valuses?? Like system 
> call , fscanf etc..etc..

See below.

> /****************************************************
> 
> root@ubuntu:/home/net-snmp/agent/mibgroup# net-snmp-config --compile-subagent 
> ionline ionline.c
> root@ubuntu:/home/net-snmp/agent/mibgroup# ./ionline localhost &
> - 
> ****************************************************
> 
> #include <net-snmp/net-snmp-config.h>
> #include <net-snmp/net-snmp-includes.h>
> #include <net-snmp/agent/net-snmp-agent-includes.h>
> #include "ionline.h"
> #include<stdio.h>
> #include<stdlib.h>
> #include<string.h>
> #include <sys/sysinfo.h>
> 
> unsigned  long        memoryCapacity = 10;  
> 
> /*
>  * Our initialization routine, called automatically by the agent 
>  * (Note that the function name must match init_FILENAME()) 
>  */
> 
> 
> void init_ionline(void)
> {
>       netsnmp_handler_registration *reg;
>       int i;
>       const oid memoryPercentUsage _oid[] = { 1,3,6,1,4,1,21067,3,1 };
>       static netsnmp_watcher_info memoryPercentUsage _winfo;
> 
>       
> 
> FILE *pipe = NULL;
>       int j;
> 
>       system("sh jatin.sh > jatin.txt");

Here is a bug - you fail to check the return status of the call to
'system'.
        
>       pipe=fopen("jatin.txt", "r");
> 
> /*******************
> After scanf function i would have a integer value between 1 to 100
> 
> **********************/

Here is another bug. You fail to check the return status of 'fopen' and
just passes it on to 'fscanf' while not knowing if the resulting FILE*
is valid.

>       fscanf(pipe,"%d",&i);

Here is yet another bug. You do not check the return status of 'fscanf'
so you do not know if the value in 'i' is an integer value or just
garbage. Also, you do not check if the value of 'i' lies inside your
limits and so that precondition is also doubtful.

/MF





------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to