Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix warnings about sprintf() reading from its output buffer #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions concurrency-webserver/src/spin.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ int main(int argc, char *argv[]) {
while ((get_seconds() - t1) < spin_for)
sleep(1);
double t2 = get_seconds();

/* Make the response body */
char content[MAXBUF];
sprintf(content, "<p>Welcome to the CGI program (%s)</p>\r\n", buf);
sprintf(content, "%s<p>My only purpose is to waste time on the server!</p>\r\n", content);
sprintf(content, "%s<p>I spun for %.2f seconds</p>\r\n", content, t2 - t1);
sprintf(content, "<p>Welcome to the CGI program (%s)</p>\r\n"
"<p>My only purpose is to waste time on the server!</p>\r\n"
"<p>I spun for %.2f seconds</p>\r\n", buf, t2 - t1);

/* Generate the HTTP response */
printf("Content-length: %lu\r\n", strlen(content));
printf("Content-type: text/html\r\n\r\n");
printf("%s", content);
fflush(stdout);

exit(0);
}

8 changes: 4 additions & 4 deletions concurrency-webserver/src/wclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
void client_send(int fd, char *filename) {
char buf[MAXBUF];
char hostname[MAXBUF];

gethostname_or_die(hostname, MAXBUF);

/* Form and send the HTTP request */
sprintf(buf, "GET %s HTTP/1.1\n", filename);
sprintf(buf, "%shost: %s\n\r\n", buf, hostname);
sprintf(buf, "GET %s HTTP/1.1\n"
"host: %s\n\r\n", filename, hostname);
write_or_die(fd, buf, strlen(buf));
}

Expand Down