Skip to content

Commit

Permalink
Bug Fixes and Performance Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nixrajput committed Jul 23, 2024
1 parent 8add509 commit 16b3a3f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/Bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ using namespace std;
// Initialie variables in constructor
Bus::Bus()
{
strcpy(busNo, "");
strlcpy(busNo, "");
maxSeats = 32;
bookedSeats = 0;
busFare = 0.0;
strcpy(source, "");
strcpy(destination, "");
strcpy(sourceTime, "");
strcpy(destinationTime, "");
strlcpy(source, "");
strlcpy(destination, "");
strlcpy(sourceTime, "");
strlcpy(destinationTime, "");
}

// Display bus details
Expand Down
10 changes: 6 additions & 4 deletions src/Bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <iostream>

#include "utils.h"

using namespace std;

// BUS CLASS
Expand Down Expand Up @@ -82,25 +84,25 @@ class Bus
void setSource(char *s)
{
if (s && s[0])
strcpy(source, s);
strlcpy(source, s);
}

void setDestination(char *d)
{
if (d && d[0])
strcpy(destination, d);
strlcpy(destination, d);
}

void setSourceTime(char *s)
{
if (s && s[0])
strcpy(sourceTime, s);
strlcpy(sourceTime, s);
}

void setDestinationTime(char *d)
{
if (d && d[0])
strcpy(destinationTime, d);
strlcpy(destinationTime, d);
}

void setBusFare(double f)
Expand Down
6 changes: 3 additions & 3 deletions src/Reservation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Reservation::Reservation() {}
// Generate a ticket
void Reservation::_generateTicket(char *n, Bus b)
{
strcpy(name, n);
strcpy(pnrNo, generatePNR(99999).c_str());
strcpy(date, getCurrentDate().c_str());
strlcpy(name, n);
strlcpy(pnrNo, generatePNR(99999).c_str());
strlcpy(date, getCurrentDate().c_str());
bus = b;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Reservation.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <iostream>

#include "Bus.h"
#include "utils.h"

// RESERVATION CLASS
class Reservation
Expand Down Expand Up @@ -49,7 +50,7 @@ class Reservation
void setName(char *n)
{
if (n && n[0])
strcpy(name, n);
strlcpy(name, n);
}
};

Expand Down
23 changes: 21 additions & 2 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

#include <cstdlib>
#include <string>
#include <cstring>
#include <limits>
#include <ctime>
#include <stddef.h>

using namespace std;