Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Use the program Test7Assignment.c and explain all the errorsagged of by splint

ID: 3833049 • Letter: 1

Question

1.Use the program Test7Assignment.c and explain all the errorsagged of by splint.

#include

#include

#include

#include"mstring.h"
/*@+showconstraintparens -modifies =showfunc@*/

// run with ansi-reserved flag on for customized naming conventions
extern int *glob;int glob1,glob2;
typedef enum {

YES, NO, DEFINITELY,PROBABLY, MAYBE } switch_variable;


char firsterror(/*@null@*/ char *x) ////1.Dereferencing null pointer{

return *x;

}

int seconderror(/*@out@*/ int *x, int i){

return getVal (x);

}

int getVal(/*@in@*/int *x){

*x=5;return 1;

}
int fourtherror(void){

return (isPalindrome ("bob"));

}
int isPalindrome (mstring s){

char *current = (char *) s;

int i, len = (int) strlen (s);

for (i = 0; i <= (len+1) / 2; i++)

{
if (current[i] != s[len-i-1])return 0;}

return 1;

}
int *fiftherror(int *x, int *y, int *z){

int *m = (int *)malloc (sizeof (int));

glob = y;free (x);*m = *x;return z;

}
void sixtherror( char *a, char *b){

strcpy(a,b);*a = toupper(*a);

}

void setx (int *x, int *y)/*@modifies *x@*/{

*y = *x;

}

void seventherror (int *x, int *y)/*@modifies *y@*/{

setx (y, x);

}

int f (void) /*@globals glob1;@*/{

return glob2;

}

void eightherror (switch_variable y){

switch (y){

case PROBABLY:case NO: printf ("No!");

case MAYBE: printf ("Maybe");

/*@fallthrough@*/

case YES: printf ("Yes!");

}

}
void strs() ////// 10.2. Customized naming conventions{}
int main(){char *v1=NULL, v3, *v9 = "Hello" , *v10;int *v2, v4 = 4, v5, *v6, *v7, *v8, *v11, *v12;

switch_variable y;firsterror(v1);   // 1.Dereferencing a possibly null pointer

seconderror(v2, 4); // 2.Using possibly undefined storage or returning storage that is not properly defined

return 0;v3=v4;    // 3. Type mismatches, with greater precision and flexibility than provided by C compilers

v5 = fourtherror(); // 4. Violation of information hiding

fiftherror (v6,v7,v8); // 5. Memory management errors including uses of dangling references and memory leaks

sixtherror (v9,v10); // 6. Dangerous aliasin

seventherror(v11,v12);// 7. Modifications and global variable uses that are inconsistent with specified interfaces

eightherror(y); // 8. Problematic control flow such as likely infiniteloops, fall through cases or incomplete switches, and suspicious statements,implemented switch cases

// 10. Dangerous macro implementations or invocations and Violationsof customized naming conventions

}

2. Use the program and explain all the errorsagged of by splint.

#include<stdio.h>

#include<string.h>
int global=1;

int modglobal()/*@globals global@*//*@modifies global@*/;

int dummy()/*@globals global@*//*@modifies nothing@*/;

void setter(/*@out@*/int *x);i

nt getter(/*@in@*/int *);

int func1(/*@out@*/int *,int);int main(){

signed int *x,i,retval,nothing,buff[20];char ch,*str1,*str2;

unsigned long ul;

unsigned int usint;
printf("Enter the value of an integer and a long variable. ");

scanf("%i%lu",&i,&ul);printf("Testing ");
switch(i){

case 1:

printf("Entered 1. ");

case 2:printf("Entered 2 or 1 ");

}

gets(str2);

strcpy(str1,str2);

buff[20]=10;
free(str1);
//printf("%s ",str1);str2=str1;
usint=ul;

ch=i;

retval=func1(x,i)*i++;while(nothing>dummy())
setter(x);
usint=retval;retval=modglobal();
if(retval>ul);else retval++;
return 0;

}

void setter(int *x){

int a=1;

x=&a;

}

int getter(int *x)/*@modifies *x@*/{

return *x;

}

int func1(/*@null@*/int *x,int i){

int retval;

if(i<5)return *x;

else if(i<3)

return getter(x);

else if(i<1){

setter(x);

retval=getter(x);

return retval;

}

}

int modglobal(){

++global;

return global;

}

int dummy(){return 1;}

Explanation / Answer

1)

#include"mstring.h"

extern int *glob;int glob1,glob2;
typedef enum {
YES, NO, DEFINITELY,PROBABLY, MAYBE } switch_variable;

char firsterror(/*@null@*/ char *x)
return *x;
}
int seconderror(/*@out@*/ int *x, int i){
return getVal (x);
}
int getVal(/*@in@*/int *x){
*x=5;return 1;
}
int fourtherror(void){
return (isPalindrome ("bob"));
}
int isPalindrome (mstring s){
char *current = (char *) s;
int i, len = (int) strlen (s);
for (i = 0; i <= (len+1) / 2; i++)
{
if (current[i] != s[len-i-1])return 0;}
return 1;
}
int *fiftherror(int *x, int *y, int *z){
int *m = (int *)malloc (sizeof (int));
glob = y;free (x);*m = *x;return z;
}
void sixtherror( char *a, char *b){
strcpy(a,b);*a = toupper(*a);
}
void setx (int *x, int *y)/*@modifies *x@*/{
*y = *x;
}
void seventherror (int *x, int *y)/*@modifies *y@*/{
setx (y, x);
}
int f (void) /*@globals glob1;@*/{
return glob2;
}
void eightherror (switch_variable y){
switch (y){
case PROBABLY:case NO: printf ("No!");
case MAYBE: printf ("Maybe");

case YES: printf ("Yes!");
}
}
void strs()
int main()
{
char *v1=NULL, v3, *v9 = "Hello" , *v10;
int *v2, v4 = 4, v5, *v6, *v7, *v8, *v11, *v12;
switch_variable y;firsterror(v1);   
seconderror(v2, 4);
return 0;v3=v4;   
v5 = fourtherror();
fiftherror (v6,v7,v8);
sixtherror (v9,v10);
seventherror(v11,v12);
eightherror(y);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote