Author: iratqq
Date: Sat Apr 12 12:27:01 2008
New Revision: 5414

Modified:
  trunk/emacs/callback.c
  trunk/emacs/commit.c
  trunk/emacs/commit.h
  trunk/emacs/helper.c
  trunk/emacs/key.c
  trunk/emacs/key.h
  trunk/emacs/preedit.c
  trunk/emacs/prop.c
  trunk/emacs/uim-el-agent.c
  trunk/emacs/uim-el-agent.h

Log:
* emacs/callback.c (commit_cb):
 - Sync API.
* emacs/commit.c (add_commit_string):
 - API Change. Take length of comstr.
* emacs/commit.h (add_commit_string):
 - Sync API.
* emacs/uim-el-agent.c (analyze_keyvector):
 - API Change. Take length of keyname.
* emacs/uim-el-agent.h (analyze_keyvector):
 - Sync API.
* emacs/key.c (convert_keyname_a2e):
 - API Change. Take length of keyname.
 - Use strlcpy(3).
* emacs/key.h (convert_keyname_a2e):
 - Sync.
* emacs/helper.c (helper_send_im_list):
 - Use asprintf(3).
 (helper_send_im_change_whole_desktop):
 - Ditto.
* emacs/prop.c (announce_prop_list_update):
 - Ditto.
 (show_prop):
 - Use strdup(3).
* emacs/preedit.c (add_preedit):
 - Ditto.


Modified: trunk/emacs/callback.c
==============================================================================
--- trunk/emacs/callback.c      (original)
+++ trunk/emacs/callback.c      Sat Apr 12 12:27:01 2008
@@ -44,7 +44,7 @@

  debug_printf(DEBUG_NOTE, "commit_cb\n");

-  ua->comstr = add_commit_string(ua->comstr, str);
+  ua->comstr = add_commit_string(ua->comstr, str, strlen(ua->comstr));
}



Modified: trunk/emacs/commit.c
==============================================================================
--- trunk/emacs/commit.c        (original)
+++ trunk/emacs/commit.c        Sat Apr 12 12:27:01 2008
@@ -37,7 +37,7 @@
#include "commit.h"

char *
-add_commit_string(char *comstr, const char *str)
+add_commit_string(char *comstr, const char *str, size_t len)
{
  int buflen;

@@ -58,7 +58,7 @@
        debug_printf(DEBUG_NOTE,
                                 "add_commit_string comstr: %s (%p)\n", comstr, 
comstr);

-       strcat(comstr, str);
+       strlcat(comstr, str, len);
  }

  debug_printf(DEBUG_NOTE,

Modified: trunk/emacs/commit.h
==============================================================================
--- trunk/emacs/commit.h        (original)
+++ trunk/emacs/commit.h        Sat Apr 12 12:27:01 2008
@@ -41,7 +41,7 @@

#include "output.h"

-char *add_commit_string(char *comstr, const char *str);
+char *add_commit_string(char *comstr, const char *str, size_t len);
int show_commit_string(char *comstr);
void reset_commit_string(char *comstr);


Modified: trunk/emacs/helper.c
==============================================================================
--- trunk/emacs/helper.c        (original)
+++ trunk/emacs/helper.c        Sat Apr 12 12:27:01 2008
@@ -40,7 +40,7 @@
helper_send_im_list(void)
{
  int nim, i;
-  int len = 0, buflen;
+  int buflen;
  char *buf;
  const char *current_im_name;
  uim_agent_context *ua;
@@ -63,51 +63,43 @@

#define HEADER_FORMAT "im_list\ncharset=%s\n"

-  len += strlen(HEADER_FORMAT) + strlen(ua->encoding);
-  len += strlen("selected") ;
-
  for (i = 0; i < uim_get_nr_im(ua->context); i++) {
        const char *name, *lang, *shortd;
        name = uim_get_im_name(ua->context, i);
        lang = uim_get_im_language(ua->context, i);
        shortd = uim_get_im_short_desc(ua->context, i);
-
-       len += name ? strlen(name) : 0;
-       len += lang ? strlen(lang) : 0;
-       len += shortd ? strlen(shortd) : 0;
-       len += strlen( "\t\t\t\n");
  }

-  len ++;
-
-  buf = (char *)malloc(sizeof(char) * len);
-
-  buflen = snprintf(buf, len, HEADER_FORMAT, ua->encoding);
+  buflen = asprintf(&buf,  HEADER_FORMAT, ua->encoding);

#undef HEADER_FORMAT

  for (i = 0 ; i < uim_get_nr_im(ua->context); i++) {
-       const char *name, *lang, *shortd;       
+       const char *name, *lang, *shortd;
+       char *tmpbuf;
+
        name = uim_get_im_name(ua->context, i);
        lang = uim_get_im_language(ua->context, i);
        shortd = uim_get_im_short_desc(ua->context, i);

        debug_printf(DEBUG_NOTE, " [%d] = %s %s %s\n", i, name, lang, shortd);
-
-       buflen += snprintf(buf + buflen, len - buflen,
-                                          "%s\t%s\t%s\t%s\n",
+       if (asprintf(&tmpbuf, "%s\t%s\t%s\t%s\n",
                                           name ? name : "" ,
                                           lang ? lang : "" ,
                                           shortd ? shortd : "" ,
-                                          strcmp(name,
+                                          strcmp(name,
                                                          (current_im_name == NULL ? 
"" : current_im_name))
-                                          == 0 ? "selected" : "");
+                                           == 0 ? "selected" : "") < 0 || 
tmpbuf == NULL)
+               break;
+
+       strlcat(buf, tmpbuf, buflen);
+       free(tmpbuf);
  }

  helper_send_message(buf);

  debug_printf(DEBUG_NOTE, " im_list = \"%s\"\n", buf);
-
+
  free(buf);

  if (dummy_agent_context)
@@ -282,17 +274,11 @@
void
helper_send_im_change_whole_desktop(const char *name)
{
-  int len = 0;
  char *buf;

#define HEADER_FORMAT "im_change_whole_desktop\n%s\n"

-  len += strlen(HEADER_FORMAT);
-  len += name ? strlen(name) : 0;
-
-  buf = (char *)malloc(sizeof(char) * len);
-
-  snprintf(buf, len, HEADER_FORMAT, name ? name : "");
+  asprintf(&buf, HEADER_FORMAT, name ? name : "");

  helper_send_message(buf);


Modified: trunk/emacs/key.c
==============================================================================
--- trunk/emacs/key.c   (original)
+++ trunk/emacs/key.c   Sat Apr 12 12:27:01 2008
@@ -41,24 +41,24 @@
  (for XEmacs)
*/
void
-convert_keyname_a2e(char *keyname, const char *name)
+convert_keyname_a2e(char *keyname, const char *name, size_t keyname_len)
{
  if (strcmp(name, "BS") == 0)
-       strcpy(keyname, "backspace");
+       strlcpy(keyname, "backspace", keyname_len);
  else if (strcmp(name, "TAB") == 0)
-       strcpy(keyname, "tab");
+       strlcpy(keyname, "tab", keyname_len);
  else if (strcmp(name, "RET") == 0)
-       strcpy(keyname, "return");
+       strlcpy(keyname, "return", keyname_len);
  else if (strcmp(name, "ESC") == 0)
-       strcpy(keyname, "escape");
+       strlcpy(keyname, "escape", keyname_len);
  else if (strcmp(name, "DEL") == 0)
-       strcpy(keyname, "delete");
+       strlcpy(keyname, "delete", keyname_len);
  else if (strcmp(name, "DEL") == 0)
-       strcpy(keyname, "delete");
+       strlcpy(keyname, "delete", keyname_len);
  else if (strcmp(name, "SPC") == 0)
-       strcpy(keyname, "space");
+       strlcpy(keyname, "space", keyname_len);
  else
-       strcpy(keyname, name);
+       strlcpy(keyname, name, keyname_len);
}



Modified: trunk/emacs/key.h
==============================================================================
--- trunk/emacs/key.h   (original)
+++ trunk/emacs/key.h   Sat Apr 12 12:27:01 2008
@@ -43,7 +43,7 @@

#include "uim-el-types.h"

-void convert_keyname_a2e(char *keyname, const char *name);
+void convert_keyname_a2e(char *keyname, const char *name, size_t len);
enum UKey convert_keyname_e2u( const char *keyname );

#endif

Modified: trunk/emacs/preedit.c
==============================================================================
--- trunk/emacs/preedit.c       (original)
+++ trunk/emacs/preedit.c       Sat Apr 12 12:27:01 2008
@@ -65,8 +65,7 @@
  }

  if (strlen(str) > 0) {
-       pb->str = (char *)malloc(strlen(str) + 1);
-       strcpy(pb->str, str);
+       pb->str = strdup(str);
        pe->length += strlen(str);
  } else {
        pb->str = NULL;

Modified: trunk/emacs/prop.c
==============================================================================
--- trunk/emacs/prop.c  (original)
+++ trunk/emacs/prop.c  Sat Apr 12 12:27:01 2008
@@ -69,7 +69,6 @@
void
announce_prop_list_update(property *prop, const char *encoding)
{
-  unsigned len;
  char *buf;

  if (prop->list == NULL) {
@@ -79,11 +78,7 @@

#define PROP_LIST_FORMAT "prop_list_update\ncharset=%s\n%s"

-  len = strlen(PROP_LIST_FORMAT) + strlen(encoding)
-       + strlen(prop->list) + 1;
-
-  buf = (char *)malloc(len);
-  snprintf(buf, len, PROP_LIST_FORMAT, encoding, prop->list);
+  asprintf(&buf, PROP_LIST_FORMAT, encoding, prop->list);

  helper_send_message(buf);
  free(buf);
@@ -111,10 +106,7 @@

  a_printf(" ( l ");

-  buf = (char *)malloc(strlen(prop->list) + 1);
-  strcpy(buf, prop->list);
-
-  head = buf;
+  head = buf = strdup(prop->list);

#define PART_BRANCH "branch"
#define PART_LEAF   "leaf"

Modified: trunk/emacs/uim-el-agent.c
==============================================================================
--- trunk/emacs/uim-el-agent.c  (original)
+++ trunk/emacs/uim-el-agent.c  Sat Apr 12 12:27:01 2008
@@ -49,8 +49,6 @@

#include "uim-el-agent.h"

-
-
/* called when owner buffer is killed  */
static int
cmd_release(int context_id)
@@ -420,7 +418,7 @@


static int
-analyze_keyvector(char *vector, uim_key *ukey, char *keyname)
+analyze_keyvector(char *vector, uim_key *ukey, char *keyname, size_t 
keyname_len)
{
  char *p1, *p2, *c;
  int key;
@@ -523,9 +521,9 @@
                        if (*p1 >= 'A' && *p1 <= 'Z')
                          /* if the first character is upper case,
                                 it can be considered as XEmacs style abbrev */
-                         convert_keyname_a2e(keyname, p1);
+                               convert_keyname_a2e(keyname, p1, keyname_len);
                        else
-                         strcpy(keyname, p1);
+                       strlcpy(keyname, p1, keyname_len);

                        ukey->key = convert_keyname_e2u(keyname);
                  }
@@ -721,7 +719,7 @@
          keyname[0] = '\0';


-         if (analyze_keyvector(p1, &ukey, keyname) > 0) {
+         if (analyze_keyvector(p1, &ukey, keyname, sizeof(keyname)) > 0) {

                a_printf("( %d %d ", serial, cid);
                if (process_keyvector(serial, cid, ukey, keyname) < 0)

Modified: trunk/emacs/uim-el-agent.h
==============================================================================
--- trunk/emacs/uim-el-agent.h  (original)
+++ trunk/emacs/uim-el-agent.h  Sat Apr 12 12:27:01 2008
@@ -72,7 +72,7 @@
static int process_command(int serial, int cid, char *cmd);
static int process_keyvector(int serial, int cid,
                                                         uim_key ukey, const 
char *keyname);
-static int analyze_keyvector(char *vector, uim_key *ukey, char *keyname);
+static int analyze_keyvector(char *vector, uim_key *ukey, char *keyname, size_t keyname_len);

void cleanup(void);

Reply via email to