patch-lib_wnutil_c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. $OpenBSD: patch-lib_wnutil_c,v 1.2 2014/11/30 05:41:35 brad Exp $
  2. Don't use malloc.h header on OpenBSD.
  3. --- lib/wnutil.c.orig Sat Jan 20 15:50:23 2007
  4. +++ lib/wnutil.c Thu Nov 20 01:29:11 2014
  5. @@ -14,9 +14,11 @@
  6. #ifdef __unix__
  7. #ifndef __MACH__
  8. +#ifndef __OpenBSD__
  9. #include <malloc.h>
  10. #endif
  11. #endif
  12. +#endif
  13. #include <assert.h>
  14. #include <string.h>
  15. @@ -48,7 +50,7 @@ int wninit(void)
  16. char *env;
  17. if (!done) {
  18. - if (env = getenv("WNDBVERSION")) {
  19. + if ((env = getenv("WNDBVERSION")) != NULL) {
  20. wnrelease = strdup(env); /* set release */
  21. assert(wnrelease);
  22. }
  23. @@ -70,7 +72,7 @@ int re_wninit(void)
  24. closefps();
  25. - if (env = getenv("WNDBVERSION")) {
  26. + if ((env = getenv("WNDBVERSION")) != NULL) {
  27. wnrelease = strdup(env); /* set release */
  28. assert(wnrelease);
  29. }
  30. @@ -149,25 +151,25 @@ static int do_init(void)
  31. sprintf(searchdir, DEFAULTPATH);
  32. #else
  33. if ((env = getenv("WNSEARCHDIR")) != NULL)
  34. - strcpy(searchdir, env);
  35. + snprintf(searchdir, sizeof(searchdir), "%s", env);
  36. else if ((env = getenv("WNHOME")) != NULL)
  37. - sprintf(searchdir, "%s%s", env, DICTDIR);
  38. + snprintf(searchdir, sizeof(searchdir), "%s%s", env, DICTDIR);
  39. else
  40. strcpy(searchdir, DEFAULTPATH);
  41. #endif
  42. for (i = 1; i < NUMPARTS + 1; i++) {
  43. - sprintf(tmpbuf, DATAFILE, searchdir, partnames[i]);
  44. + snprintf(tmpbuf, sizeof(tmpbuf), DATAFILE, searchdir, partnames[i]);
  45. if((datafps[i] = fopen(tmpbuf, "r")) == NULL) {
  46. - sprintf(msgbuf,
  47. + snprintf(msgbuf, sizeof(msgbuf),
  48. "WordNet library error: Can't open datafile(%s)\n",
  49. tmpbuf);
  50. display_message(msgbuf);
  51. openerr = -1;
  52. }
  53. - sprintf(tmpbuf, INDEXFILE, searchdir, partnames[i]);
  54. + snprintf(tmpbuf, sizeof(tmpbuf), INDEXFILE, searchdir, partnames[i]);
  55. if((indexfps[i] = fopen(tmpbuf, "r")) == NULL) {
  56. - sprintf(msgbuf,
  57. + snprintf(msgbuf, sizeof(msgbuf),
  58. "WordNet library error: Can't open indexfile(%s)\n",
  59. tmpbuf);
  60. display_message(msgbuf);
  61. @@ -178,35 +180,35 @@ static int do_init(void)
  62. /* This file isn't used by the library and doesn't have to
  63. be present. No error is reported if the open fails. */
  64. - sprintf(tmpbuf, SENSEIDXFILE, searchdir);
  65. + snprintf(tmpbuf, sizeof(tmpbuf), SENSEIDXFILE, searchdir);
  66. sensefp = fopen(tmpbuf, "r");
  67. /* If this file isn't present, the runtime code will skip printint out
  68. the number of times each sense was tagged. */
  69. - sprintf(tmpbuf, CNTLISTFILE, searchdir);
  70. + snprintf(tmpbuf, sizeof(tmpbuf), CNTLISTFILE, searchdir);
  71. cntlistfp = fopen(tmpbuf, "r");
  72. /* This file doesn't have to be present. No error is reported if the
  73. open fails. */
  74. - sprintf(tmpbuf, KEYIDXFILE, searchdir);
  75. + snprintf(tmpbuf, sizeof(tmpbuf), KEYIDXFILE, searchdir);
  76. keyindexfp = fopen(tmpbuf, "r");
  77. - sprintf(tmpbuf, REVKEYIDXFILE, searchdir);
  78. + snprintf(tmpbuf, sizeof(tmpbuf), REVKEYIDXFILE, searchdir);
  79. revkeyindexfp = fopen(tmpbuf, "r");
  80. - sprintf(tmpbuf, VRBSENTFILE, searchdir);
  81. + snprintf(tmpbuf, sizeof(tmpbuf), VRBSENTFILE, searchdir);
  82. if ((vsentfilefp = fopen(tmpbuf, "r")) == NULL) {
  83. - sprintf(msgbuf,
  84. + snprintf(msgbuf, sizeof(msgbuf),
  85. "WordNet library warning: Can't open verb example sentence file(%s)\n",
  86. tmpbuf);
  87. display_message(msgbuf);
  88. }
  89. - sprintf(tmpbuf, VRBIDXFILE, searchdir);
  90. + snprintf(tmpbuf, sizeof(tmpbuf), VRBIDXFILE, searchdir);
  91. if ((vidxfilefp = fopen(tmpbuf, "r")) == NULL) {
  92. - sprintf(msgbuf,
  93. + snprintf(msgbuf, sizeof(msgbuf),
  94. "WordNet library warning: Can't open verb example sentence index file(%s)\n",
  95. tmpbuf);
  96. display_message(msgbuf);