Browse Source

dselect: Do not use fixed size strings for menu entries

Guillem Jover 8 years ago
parent
commit
58876fceaf
3 changed files with 10 additions and 11 deletions
  1. 1 0
      debian/changelog
  2. 8 7
      dselect/main.cc
  3. 1 4
      dselect/method.cc

+ 1 - 0
debian/changelog

@@ -9,6 +9,7 @@ dpkg (1.18.7) UNRELEASED; urgency=medium
     many cases could cause confusing truncation of long messages. Use heap
     allocated formatted strings instead:
     - In start-stop-daemon to report what to stop.
+    - In dselect to print main and access methods menu entries.
   * Perl modules:
     - Relax dependency restrictions parsing to allow again sloppy spaces
       around versions, architectures and profile restrictions.

+ 8 - 7
dselect/main.cc

@@ -394,9 +394,10 @@ urqresult urq_list(void) {
 static void
 dme(int i, int so)
 {
-  char buf[120];
   const menuentry *me= &menuentries[i];
-  sprintf(buf," %c %d. %-11.11s %-80.80s ",
+
+  varbuf buf;
+  buf.fmt(" %c %d. %-11.11s %-80.80s ",
           so ? '*' : ' ', i,
           gettext(me->option),
           gettext(me->menuent));
@@ -405,24 +406,24 @@ dme(int i, int so)
   getmaxyx(stdscr,y,x);
 
   attrset(so ? A_REVERSE : A_NORMAL);
-  mvaddnstr(i+2,0, buf,x-1);
+  mvaddnstr(i + 2, 0, buf.string(), x - 1);
   attrset(A_NORMAL);
 }
 
 static int
 refreshmenu(void)
 {
-  char buf[2048];
-
   curseson(); cbreak(); noecho(); nonl(); keypad(stdscr,TRUE);
 
   int x, y DPKG_ATTR_UNUSED;
   getmaxyx(stdscr,y,x);
 
+  varbuf buf;
+  buf.fmt(gettext(programdesc), DSELECT, PACKAGE_RELEASE);
+
   clear();
   attrset(A_BOLD);
-  sprintf(buf, gettext(programdesc), DSELECT, PACKAGE_RELEASE);
-  mvaddnstr(0,0,buf,x-1);
+  mvaddnstr(0, 0, buf.string(), x - 1);
 
   attrset(A_NORMAL);
   const struct menuentry *mep; int i;

+ 1 - 4
dselect/method.cc

@@ -59,12 +59,9 @@ static int methlockfd= -1;
 static void
 sthfailed(const char * reasoning)
 {
-  char buf[2048];
-
   curseson();
   clear();
-  sprintf(buf,_("\n\n%s: %s\n"),DSELECT,reasoning);
-  addstr(buf);
+  printw(_("\n\n%s: %s\n"), DSELECT, reasoning);
   attrset(A_BOLD);
   addstr(_("\nPress <enter> to continue."));
   attrset(A_NORMAL);