Do you check all error conditions for all library calls in you code?
Is it necessary to check all errors? Is it convenient to check all
errors (or how to make code clean and readable with mass of non
business logic related code block)?
The following code from net-snmp library calls atoi five times but
checks none. Do we code a wrapper my_atoi_with_er ror_check() around
atoi and call this new one everywhere else? Is it a good practice (If
it is, why ANSI atoi doesn't do it)?
/* <quote file=../net-snmp-5.4.1.1/snmplib/vacm.c*/
286 char *
287 _vacm_parse_con fig_access_comm on(struct vacm_accessEntr y
**aptr, char *line)
288 {
289 struct vacm_accessEntr y access;
290 char *cPrefix = (char *) &access.context Prefix;
291 char *gName = (char *) &access.groupNa me;
292 size_t len;
293
294 access.status = atoi(line);
295 line = skip_token(line );
296 access.storageT ype = atoi(line);
297 line = skip_token(line );
298 access.security Model = atoi(line);
299 line = skip_token(line );
300 access.security Level = atoi(line);
301 line = skip_token(line );
302 access.contextM atch = atoi(line);
303 line = skip_token(line );
304 len = sizeof(access.g roupName);
305 line = read_config_rea d_octet_string( line, (u_char **)
&gName, &len);
306 len = sizeof(access.c ontextPrefix);
307 line = read_config_rea d_octet_string( line, (u_char **)
&cPrefix, &len);
308
309 *aptr = vacm_getAccessE ntry(access.gro upName,
310 access.contextP refix,
311 access.security Model,
312 access.security Level);
313 if (!*aptr)
314 *aptr = vacm_createAcce ssEntry(access. groupName,
315 access.contextP refix,
316 access.security Model,
317 access.security Level);
318 if (!*aptr)
319 return NULL;
320
321 (*aptr)->status = access.status;
322 (*aptr)->storageType = access.storageT ype;
323 (*aptr)->securityMode l = access.security Model;
324 (*aptr)->securityLeve l = access.security Level;
325 (*aptr)->contextMatch = access.contextM atch;
326 return line;
327 }
/* </quote*/
Is it necessary to check all errors? Is it convenient to check all
errors (or how to make code clean and readable with mass of non
business logic related code block)?
The following code from net-snmp library calls atoi five times but
checks none. Do we code a wrapper my_atoi_with_er ror_check() around
atoi and call this new one everywhere else? Is it a good practice (If
it is, why ANSI atoi doesn't do it)?
/* <quote file=../net-snmp-5.4.1.1/snmplib/vacm.c*/
286 char *
287 _vacm_parse_con fig_access_comm on(struct vacm_accessEntr y
**aptr, char *line)
288 {
289 struct vacm_accessEntr y access;
290 char *cPrefix = (char *) &access.context Prefix;
291 char *gName = (char *) &access.groupNa me;
292 size_t len;
293
294 access.status = atoi(line);
295 line = skip_token(line );
296 access.storageT ype = atoi(line);
297 line = skip_token(line );
298 access.security Model = atoi(line);
299 line = skip_token(line );
300 access.security Level = atoi(line);
301 line = skip_token(line );
302 access.contextM atch = atoi(line);
303 line = skip_token(line );
304 len = sizeof(access.g roupName);
305 line = read_config_rea d_octet_string( line, (u_char **)
&gName, &len);
306 len = sizeof(access.c ontextPrefix);
307 line = read_config_rea d_octet_string( line, (u_char **)
&cPrefix, &len);
308
309 *aptr = vacm_getAccessE ntry(access.gro upName,
310 access.contextP refix,
311 access.security Model,
312 access.security Level);
313 if (!*aptr)
314 *aptr = vacm_createAcce ssEntry(access. groupName,
315 access.contextP refix,
316 access.security Model,
317 access.security Level);
318 if (!*aptr)
319 return NULL;
320
321 (*aptr)->status = access.status;
322 (*aptr)->storageType = access.storageT ype;
323 (*aptr)->securityMode l = access.security Model;
324 (*aptr)->securityLeve l = access.security Level;
325 (*aptr)->contextMatch = access.contextM atch;
326 return line;
327 }
/* </quote*/
Comment