Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

do a git checkout infinite_loop command to checkout the infinite_loop branch of the project. This version contains an infinite that you must diagnose. What is

do a git checkout infinite_loop command to checkout the infinite_loop branch of the project. This version contains an infinite that you must diagnose.

  1. What is the proximate error, and where in the source code does it occur?
  2. What is the root error, and where in the source code does it occur?
  3. What indications of an error are displayed in the program's presentation?
  4. What indications of an error are displayed in the program's valgrind profile?
  5. What is the sequence of gdb commands you used to identify the location of the root and proximate errors?
  6. What fix would you suggest for this bug?

#pragma once #include // Only library we get

int strlen(const char *); // User-defined strlen function int strcmp(const char *, const char *); // User-defined strcmp function int main(int, char **, char **); // Standard main function

// Debug 1 Project: List of command line arguments and environment variables #include "main.h"

int main(int argc, char **argv, char **envp) { // List Control int envc = 0; // Length of envp array int size = 0; // Number of elements stored in our list for (envc = 0; envp[envc] != nullptr; envc++); // Count number of environment variables int capacity = argc + envc; // Size of list needed (command line args + environment vars) char * list[capacity]; // The list bool found = false; // List search result int position = 0; // List insertion position

// Add command line arguments to the list: ordered, no duplicates for (auto idx = 0; idx < argc; idx++) { found = false; // Reset search result for(position = 0; position < size; position++) { if (strcmp(list[position],argv[idx]) == 0) { found = true; break; } if (strcmp(list[position], argv[idx]) > 0) { found = false; break; } } if (found == false) { for (auto ptr = size; ptr > position; ptr--) list[ptr] = list[ptr - 1];

list[position] = argv[idx]; size++; } }

// Add environment variables to the list: ordered, no duplicates for (auto idx = 0; idx < envc; idx++) { found = false; // Reset search result for(position = 0; position < size; position++) { if (strcmp(list[position],envp[idx]) == 0) { found = true; break; } if (strcmp(list[position], envp[idx]) > 0) { found = false; break; } } if (found == false) { for (auto ptr = size; ptr > position; ptr--) list[ptr] = list[ptr - 1]; list[position] = envp[idx]; size++; } }

// Display the list

std::cout << "List: " << std::endl ; for(auto idx = 0; idx < size; idx++) { std::cout << list[idx] << std::endl ; }

return 0; }

/* Purpose: Calculate and return length of C-String Parameters const char * string is the pointer to the C-string. The 'const' is needed so we can accept argv and envp strings Return: int length of c-string (not counting the null terminator) */ int strlen(const char * string) { int result = 0; // Result for(result = 0; string[result] != '\0'; result++);// Counting loop return result; // Return the count

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions