[2738] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

Re: Pile of random cleanup patches

daemon@ATHENA.MIT.EDU (Anders Kaseorg)
Sat Nov 6 18:46:52 2010

Date: Sat, 6 Nov 2010 18:46:49 -0400 (EDT)
From: Anders Kaseorg <andersk@MIT.EDU>
To: David A Benjamin <davidben@mit.edu>
cc: barnowl-dev@mit.edu
In-Reply-To: <alpine.DEB.1.10.1010302222580.15631@dr-wily.mit.edu>

On Sat, 30 Oct 2010, David A Benjamin wrote:
> In retrospect, it appears I forgot to put the variable declarations at=20
> the top of the block, if we care.

There was one other violation, so 5bdce2e is a separate patch to fix that.

> It looks like ZWRITEOPTIONS.message tends to be malloc'd from BuildArgStr=
ing?
> There's certainly not much point in free'ing it, but storing as const fee=
ls
> somewhat off? signature comes from optarg, so I guess the const is correc=
t
> there? I almost wonder if we want to strdup it for consistency, but it al=
l
> seems a little silly.

Repushed as 971087b with const removed from message.

Patches below and at git://andersk.mit.edu/barnowl.git cleanup.

Anders

-- 8< --
From=20971087bb44561c6a32fe6c16d1550c8fb7ca8f2a Mon Sep 17 00:00:00 2001
From: Anders Kaseorg <andersk@mit.edu>
Date: Tue, 26 Oct 2010 00:33:17 -0400
Subject: [PATCH 1/2] zcrypt: Make strings const

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
---
 zcrypt.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/zcrypt.c b/zcrypt.c
index f488a69..ea7b816 100644
--- a/zcrypt.c
+++ b/zcrypt.c
@@ -49,7 +49,7 @@
 typedef struct
 {
   int flags;
-  char *signature;
+  const char *signature;
   char *message;
 } ZWRITEOPTIONS;
=20
@@ -109,7 +109,7 @@ int main(int argc, char *argv[])
   int cipher;
   int error =3D FALSE;
   int zephyr =3D FALSE;
-  char *class =3D NULL, *instance =3D NULL;
+  const char *class =3D NULL, *instance =3D NULL;
   int mode =3D M_NONE;
=20
   char c;
--=20
1.7.3.2


From=205bdce2e8c0c64feaa7aa8722b2500173ba998f7b Mon Sep 17 00:00:00 2001
From: Anders Kaseorg <andersk@mit.edu>
Date: Sat, 6 Nov 2010 18:40:11 -0400
Subject: [PATCH 2/2] Move declarations before code
MIME-Version: 1.0
Content-Type: text/plain; charset=3DUTF-8
Content-Transfer-Encoding: 8bit

I don=E2=80=99t know if we still care about this, but we had few enough
violations that we might as well fix them.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
---
 commands.c |    6 +++---
 window.c   |    8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/commands.c b/commands.c
index 5cbe262..aa48ac4 100644
--- a/commands.c
+++ b/commands.c
@@ -1319,14 +1319,14 @@ char *owl_command_smartnarrow(int argc, const char =
*const *argv, const char *buf
   int instance =3D 0, related =3D 0, i;
   const char **tmp_argv =3D owl_malloc(sizeof(char *) * argc);
=20
-  for (i =3D 0; i < argc; i++)
-    tmp_argv[i] =3D argv[i];
-
   static const struct option options[] =3D {
     {"instance", 0, 0, 'i'},
     {"related",  0, 0, 'r'},
     {NULL,       0, 0, 0}};
=20
+  for (i =3D 0; i < argc; i++)
+    tmp_argv[i] =3D argv[i];
+
   optind =3D 0;
   while ((opt =3D getopt_long(argc, (char **)tmp_argv, "ir", options, NULL=
)) !=3D -1) {
     switch (opt) {
diff --git a/window.c b/window.c
index ae19815..61735fe 100644
--- a/window.c
+++ b/window.c
@@ -296,8 +296,8 @@ void owl_window_show(owl_window *w)
=20
 void owl_window_show_all(owl_window *w)
 {
-  owl_window_show(w);
   FuncOneArg ptr =3D (FuncOneArg)owl_window_show;
+  owl_window_show(w);
   owl_window_children_foreach(w, first_arg_only, &ptr);
 }
=20
@@ -347,6 +347,7 @@ static void _owl_window_realize_later(owl_window *w)
=20
 static void _owl_window_realize(owl_window *w)
 {
+  FuncOneArg ptr =3D (FuncOneArg)_owl_window_realize_later;
   /* check if we can create a window */
   if (owl_window_is_realized(w) || !_owl_window_should_realize(w))
     return;
@@ -358,16 +359,15 @@ static void _owl_window_realize(owl_window *w)
   /* schedule a repaint */
   owl_window_dirty(w);
   /* map the children */
-  FuncOneArg ptr =3D (FuncOneArg)_owl_window_realize_later;
   owl_window_children_foreach(w, first_arg_only, &ptr);
 }
=20
 static void _owl_window_unrealize(owl_window *w)
 {
+  FuncOneArg ptr =3D (FuncOneArg)_owl_window_unrealize;
   if (w->win =3D=3D NULL)
     return;
   /* unmap all the children */
-  FuncOneArg ptr =3D (FuncOneArg)_owl_window_unrealize;
   owl_window_children_foreach(w, first_arg_only, &ptr);
   _owl_window_destroy_curses(w);
   w->dirty =3D w->dirty_subtree =3D 0;
@@ -444,10 +444,10 @@ static void _owl_window_redraw(owl_window *w)
=20
 static void _owl_window_redraw_subtree(owl_window *w)
 {
+  FuncOneArg ptr =3D (FuncOneArg)_owl_window_redraw_subtree;
   if (!w->dirty_subtree)
     return;
   _owl_window_redraw(w);
-  FuncOneArg ptr =3D (FuncOneArg)_owl_window_redraw_subtree;
   owl_window_children_foreach(w, first_arg_only, &ptr);
   w->dirty_subtree =3D 0;
 }
--=20
1.7.3.2


home help back first fref pref prev next nref lref last post