Skip to content

Commit

Permalink
Changed all the sprintf calls to snprintf to keep apple compiler happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayne Cripps committed Nov 11, 2023
1 parent ad1e252 commit b1bc4fd
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion dviprint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ void dvi_print::p_num(int n)
#ifdef MAC
string[0] = 0;
#else
sprintf(string, "%d", n);
snprintf(string, sizeof(string), "%d", n);
#endif
push();
movev("0.18 in");
Expand Down
4 changes: 2 additions & 2 deletions getsys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ do_music(i_buf *ib, unsigned char staff[], char buf[], int *l_p, int *skip,
for (i=2; i < STAFF; i++) buff[i] = ' ';
}
#else
sprintf(buff, "%cM ", music[b]);
snprintf(buff, sizeof(buff), "%cM ", music[b]);
#endif
else if (staff[1] == 'R' )
#ifdef MAC
Expand All @@ -1261,7 +1261,7 @@ do_music(i_buf *ib, unsigned char staff[], char buf[], int *l_p, int *skip,
for (i=3; i < STAFF; i++) buff[i] = ' ';
}
#else
sprintf(buff, "%cR%c ", staff[0], staff[2]); /* get the dot */
snprintf(buff, sizeof(buff), "%cR%c ", staff[0], staff[2]); /* get the dot */
#endif
else {
for ( ; i< STAFF; i++) staff[i] = ' ';
Expand Down
6 changes: 3 additions & 3 deletions midi_snd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ midi_snd::midi_snd()
buffer = new i_buf();
midi_head();
count = 0;
sprintf(s, "tab %s copyright 1995-2024 by Wayne Cripps", VERSION);
snprintf(s, 50, "tab %s copyright 1995-2024 by Wayne Cripps", VERSION);
text(Copyright, s);
text(Text, "converted by TAB");
instmnt = 0;
Expand All @@ -39,7 +39,7 @@ midi_snd::midi_snd(const unsigned int instrument, const unsigned int volume,
buffer = new i_buf();
midi_head();
count = 0;
sprintf(s, "tab %s copyright 1995-2020 by Wayne Cripps", VERSION);
snprintf(s, sizeof(s), "tab %s copyright 1995-2020 by Wayne Cripps", VERSION);
text(Copyright, s);
text(Text, "converted by TAB");
text(Text, infile);
Expand All @@ -60,7 +60,7 @@ midi_snd::midi_snd(const unsigned int instrument,
buffer = new i_buf();
midi_head();
count = 0;
sprintf(s, "tab %s copyright 1995-2020 by Wayne Cripps", VERSION);
snprintf(s, sizeof(s), "tab %s copyright 1995-2020 by Wayne Cripps", VERSION);
text(Copyright, s);
text(Text, "converted by TAB");
text(Text, infile);
Expand Down
2 changes: 1 addition & 1 deletion nmidi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void nmidi::do_lute_music()
for (i=0; i< STRINGS; i++)
saved[i] = 0;

sprintf(s, "tab %s copyright 1995-2018 by Wayne Cripps", VERSION);
snprintf(s, (size_t)sizeof(s), "tab %s copyright 1995-2023 by Wayne Cripps", VERSION);
ntext(Copyright, s);
ntext(Text, "converted by TAB");
ntext(Track, "lute");
Expand Down
14 changes: 5 additions & 9 deletions pass1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,11 @@ void pass1(font_list *f_a[], int *l_p, struct file_info *f, double *extra)

foo = (char *) malloc(45);
chart[2].width = foo; /* w */
sprintf(wp[2].width, "%.3f in", 1.2 * rt * rt * rt * base_sp);

// sprintf(chart[3].width, "%.3f in", rt * rt * rt * base_sp); /* 0 flags */
sprintf(wp[3].width, "%.3f in", (f_a[0]->fnt->get_width(bf_num[3]))); /* 0 flags */
// sprintf(chart[4].width, "%.3f in", rt * rt * base_sp); /* 1 flags */
sprintf(wp[4].width, "%.3f in", (f_a[0]->fnt->get_width(bf_num[4]))); /* 1 flags */
// sprintf(chart[5].width, "%.3f in", rt * base_sp); /* 2 flags */
sprintf(wp[5].width, "%.3f in", f_a[0]->fnt->get_width(bf_num[5])); /* 2 flags */
sprintf(wp[6].width, "%.3f in", f_a[0]->fnt->get_width(bf_num[6])); /* 3 flags */
snprintf(wp[2].width, sizeof(wp[2].width), "%.3f in", 1.2 * rt * rt * rt * base_sp);
snprintf(wp[3].width, sizeof(wp[3].width), "%.3f in", (f_a[0]->fnt->get_width(bf_num[3])));/* 0 flags */
snprintf(wp[4].width, sizeof(wp[4].width), "%.3f in", (f_a[0]->fnt->get_width(bf_num[4])));/* 1 flags */
snprintf(wp[5].width, sizeof(wp[5].width), "%.3f in", f_a[0]->fnt->get_width(bf_num[5])); /* 2 flags */
snprintf(wp[6].width, sizeof(wp[6].width), "%.3f in", f_a[0]->fnt->get_width(bf_num[6])); /* 3 flags */

if (0) {
printf("pass1: init font widths \n");
Expand Down
16 changes: 8 additions & 8 deletions pdf_print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void pdf_print::file_trail() // write_postamble
file_xref();

pr_out->PutString("trailer\n");
sprintf (buf, "<< /Size %d\n", xref_count );
snprintf (buf, sizeof(buf),"<< /Size %d\n", xref_count );
pr_out->PutString(buf);
pr_out->PutString(" /Root 1 0 R\n");
pr_out->PutString(">>\n");
Expand Down Expand Up @@ -672,7 +672,7 @@ void pdf_print::p_num(int n)
double total_width=0.0;
#ifdef MAC
#else
sprintf(string, "%d", n);
snprintf(string, sizeof(string), "%d", n);
#endif
push();
movev("0.18 in");
Expand Down Expand Up @@ -839,7 +839,7 @@ void pdf_print::pdf_command(int com, int h_n, int v_n, int hh_n, int vv_n)
case MOVE:
{
double ttt=d_to_p(h); double tttt=d_to_p(-v);
sprintf (ctemp, "%.1f %.1f m \n", ttt, tttt);
snprintf (ctemp, sizeof(ctemp), "%.1f %.1f m \n", ttt, tttt);
// printf (" MOVE %.4f %.4f\n", ttt, tttt);
}
// printf (" MOVE: %.4f %.4f\n", d_to_p(h), d_to_p( -v));
Expand All @@ -848,19 +848,19 @@ void pdf_print::pdf_command(int com, int h_n, int v_n, int hh_n, int vv_n)
case RULE: // now takes x, y to draw a box 0, 0, x, y
// printf("pdf_print: RULE 847: %d %d\n", dvi_h, h);
//
sprintf (ctemp, "q %.1f %.1f %.1f %.1f re s Q \n",
snprintf (ctemp, sizeof(ctemp), "q %.1f %.1f %.1f %.1f re s Q \n",
d_to_p(dvi_h), d_to_p(dvi_v),
d_to_p(h), d_to_p(-v));
strcat (pdf_stream_b, ctemp);
break;
case MOVEH:
sprintf (ctemp, "%.1f 0 m \n", d_to_p(h));
snprintf (ctemp, sizeof(ctemp), "%.1f 0 m \n", d_to_p(h));
// printf (" MOVEH %.4f\n", d_to_p(h));
strcat (pdf_stream_b, ctemp);
break;
case MOVEV:
// if (d_to_p(dvi_v -v) < 610.0 ) { printf("HERE HERE\n");}
sprintf (ctemp, "0 %.1f m \n", d_to_p(dvi_v -v));
snprintf (ctemp, sizeof(ctemp), "0 %.1f m \n", d_to_p(dvi_v -v));
// printf (" MOVEV: %.4f\n", d_to_p(dvi_v -v));
strcat (pdf_stream_b, ctemp);
break;
Expand Down Expand Up @@ -1305,7 +1305,7 @@ unsigned int pdf_print::do_page_content(i_buf *i_b, struct font_list *f_a[])
// we need to know byte count of content stream here
// count includes trailing newline

sprintf (b, "<</Length %u>>\n", scount);
snprintf (b, sizeof(b), "<</Length %u>>\n", scount);
bytes += pr_out->PutStringC(b);

bytes += pr_out->PutStringC("stream\n");
Expand Down Expand Up @@ -1378,7 +1378,7 @@ unsigned int pdf_print::do_text_stream(i_buf *i_b, struct font_list *f_a[],
strcpy (s_buf, "BT\n/F13 12 Tf\n 288 520 Tda\n (ABC) Tj\nET \n");
scount = strlen(s_buf);
bytes += pr_out->PutStringC("6 0 obj\n<</Length ");
sprintf (b, "%d", scount);
snprintf (b, sizeof(b), "%d", scount);
bytes += pr_out->PutStringC(b);
bytes += pr_out->PutStringC(">>\nstream\n");
bytes += pr_out->PutStringC(s_buf);
Expand Down
2 changes: 1 addition & 1 deletion ps_print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ void ps_print::p_num(int n)
double total_width=0.0;
#ifdef MAC
#else
sprintf(string, "%d", n);
snprintf(string, sizeof(string), "%d", n);
#endif
push();
movev("0.18 in");
Expand Down
2 changes: 1 addition & 1 deletion tab_p.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ int format_page(print *p, i_buf *i_b,
}
if (f->flags & PAGENUM) {
char num[6];
sprintf(num, "%d", p->get_page_number());
snprintf(num, sizeof(num), "%d", p->get_page_number());
format_pagenum (p, f_a, num, f);
}
// printf("tab_p.cc: format_page: first flag_h: %f %d\n", flag_h, inch_to_dvi(flag_h)); // wbc Dec 27 2018
Expand Down

0 comments on commit b1bc4fd

Please sign in to comment.