Parts (1.1) - (1.12) correspond to twelve different versions of the fun.c program. We built & ran each version like so: $ gcc fun.c -o fun $ ./fun hey there. Your job is to determine the behavior of each version. In particular, write either "OKAY" or "ERROR" for each version of the fun.c program, as well as some additional information. Write your answers on the answer sheet, following the instructions below: - OKAY: Write "OKAY" if valgrind reports no memory errors. Note that memory leaks are okay. For this problem, we don't consider memory leaks to be errors. If you choose this option, you also must write the output of the program. If you think more than 5 lines are printed (e.g. due to an infinite loop), just write the first 5 lines. ERROR: Write "ERROR" if valgrind reports at least one memory error that is not a memory leak. If you choose this option, you also must identify the type of error that valgrind reports. Write one of A, B, C, or D: - Write "A" for invalid read - Write "B" for invalid write - Write "C" for invalid free () - Write "D" for conditional jump or move depends on uninitialised value (s) (If you think there are many memory errors, identify only the first one to occur when the program is run.) Some hints and assumptions: Assume all programs are run on a little endian machine.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Parts (1.1) - (1.12) correspond to twelve different versions of the fun.c
program. We built & ran each version like so:
$ gcc fun.c -o fun
$ ./fun hey there
Your job is to determine the behavior of each version.
In particular, write either "OKAY" or "ERROR" for each version of the fun.c
program, as well as some additional information. Write your answers on the
answer sheet, following the instructions below:
OKAY: Write "OKAY" if valgrind reports no memory errors. Note that
memory leaks are okay. For this problem, we don't consider
memory leaks to be errors.
If you choose this option, you also must write the output of
the program. If you think more than 5 lines are printed (e.g.
due to an infinite loop), just write the first 5 lines.
ERROR: Write "ERROR" if valgrind reports at least one memory error
that is not a memory leak.
If you choose this option, you also must identify the type of
error that valgrind reports. Write one of A, B, C, or D:
Write "A" for invalid read
- Write "B" for
invalid write
- Write "C" for
invalid free ()
- Write "D" for conditional jump or move depends on
uninitialised
value (s)
}
(If you think there are many memory errors, identify only the
first one to occur when the program is run.)
Some hints and assumptions:
- Assume all programs are run on a little endian machine.
printf("%s\n", NULL); causes printf() to dereference a NULL pointer,
which causes an "invalid read" memory error.
To jog your memory on argc and argv, we provide the following sample
program. All asserts succeed when we build & run as shown above.
int main (int argc, char **argv) {
assert (argc 3);
assert (strcmp (argv[0], "./fun")
assert (strcmp (argv[1], "hey")
assert (strcmp (argv[2], "there")
assert (argv[3] == NULL);
==
0);
0);
== 0);
Transcribed Image Text:Parts (1.1) - (1.12) correspond to twelve different versions of the fun.c program. We built & ran each version like so: $ gcc fun.c -o fun $ ./fun hey there Your job is to determine the behavior of each version. In particular, write either "OKAY" or "ERROR" for each version of the fun.c program, as well as some additional information. Write your answers on the answer sheet, following the instructions below: OKAY: Write "OKAY" if valgrind reports no memory errors. Note that memory leaks are okay. For this problem, we don't consider memory leaks to be errors. If you choose this option, you also must write the output of the program. If you think more than 5 lines are printed (e.g. due to an infinite loop), just write the first 5 lines. ERROR: Write "ERROR" if valgrind reports at least one memory error that is not a memory leak. If you choose this option, you also must identify the type of error that valgrind reports. Write one of A, B, C, or D: Write "A" for invalid read - Write "B" for invalid write - Write "C" for invalid free () - Write "D" for conditional jump or move depends on uninitialised value (s) } (If you think there are many memory errors, identify only the first one to occur when the program is run.) Some hints and assumptions: - Assume all programs are run on a little endian machine. printf("%s\n", NULL); causes printf() to dereference a NULL pointer, which causes an "invalid read" memory error. To jog your memory on argc and argv, we provide the following sample program. All asserts succeed when we build & run as shown above. int main (int argc, char **argv) { assert (argc 3); assert (strcmp (argv[0], "./fun") assert (strcmp (argv[1], "hey") assert (strcmp (argv[2], "there") assert (argv[3] == NULL); == 0); 0); == 0);
HINT: Be careful. Remember that argv[0] corresponds to "./fun" and the
actual command line arguments are in argv[1] and argv[2].
(1.1) int main (int argc, char **argv)
{
}
}
(1.5)
(1.2) int main (int argc, char **argv)
{
}
while (*argv++) {
}
}
(1.3) char *f (char **argv)
{
}
while (*++argv) {
}
}
printf("%s\n", *argv);
int main (int argc, char **argv)
{
return *++argv;
printf("%s\n", *argv);
}
while (f(argv)) {
(1.4) int main (int argc, char **argv)
{
}
printf("%s\n", *argv);
while (*++*argv) {
}
int main (int argc, char **argv)
{
printf("%s\n", *argv);
while ((fork () == fork () ) && *argv) {
printf("%s\n", *argv);
argv++;
Transcribed Image Text:HINT: Be careful. Remember that argv[0] corresponds to "./fun" and the actual command line arguments are in argv[1] and argv[2]. (1.1) int main (int argc, char **argv) { } } (1.5) (1.2) int main (int argc, char **argv) { } while (*argv++) { } } (1.3) char *f (char **argv) { } while (*++argv) { } } printf("%s\n", *argv); int main (int argc, char **argv) { return *++argv; printf("%s\n", *argv); } while (f(argv)) { (1.4) int main (int argc, char **argv) { } printf("%s\n", *argv); while (*++*argv) { } int main (int argc, char **argv) { printf("%s\n", *argv); while ((fork () == fork () ) && *argv) { printf("%s\n", *argv); argv++;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Fibonacci algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education