| File: | src/xlibi18n/lcPublic.c |
| Location: | line 87, column 17 |
| Description: | Result of 'calloc' is converted to a pointer of type 'struct XLCdCoreRec', which is incompatible with sizeof operand type 'XLCdPublicRec' |
| 1 | /* |
| 2 | * Copyright 1992, 1993 by TOSHIBA Corp. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and distribute this software and its |
| 5 | * documentation for any purpose and without fee is hereby granted, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of TOSHIBA not be used in advertising |
| 9 | * or publicity pertaining to distribution of the software without specific, |
| 10 | * written prior permission. TOSHIBA make no representations about the |
| 11 | * suitability of this software for any purpose. It is provided "as is" |
| 12 | * without express or implied warranty. |
| 13 | * |
| 14 | * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING |
| 15 | * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL |
| 16 | * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR |
| 17 | * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
| 18 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
| 19 | * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
| 20 | * SOFTWARE. |
| 21 | * |
| 22 | * Author: Katsuhisa Yano TOSHIBA Corp. |
| 23 | * mopi@osa.ilab.toshiba.co.jp |
| 24 | */ |
| 25 | |
| 26 | #ifdef HAVE_CONFIG_H1 |
| 27 | #include <config.h> |
| 28 | #endif |
| 29 | #include <stdio.h> |
| 30 | #include "Xlibint.h" |
| 31 | #include "XlcPubI.h" |
| 32 | |
| 33 | static const char * |
| 34 | default_string( |
| 35 | XLCd lcd) |
| 36 | { |
| 37 | return XLC_PUBLIC(lcd, default_string)(((XLCdPublic) lcd->core)->pub.default_string); |
| 38 | } |
| 39 | |
| 40 | static XLCd create (const char *name, XLCdMethods methods); |
| 41 | static Boolint initialize (XLCd lcd); |
| 42 | static void destroy (XLCd lcd); |
| 43 | static char *get_values (XLCd lcd, XlcArgList args, int num_args); |
| 44 | |
| 45 | static XLCdPublicMethodsRec publicMethods = { |
| 46 | { |
| 47 | destroy, |
| 48 | _XlcDefaultMapModifiers, |
| 49 | NULL((void*)0), |
| 50 | NULL((void*)0), |
| 51 | _XrmDefaultInitParseInfo, |
| 52 | _XmbTextPropertyToTextList, |
| 53 | _XwcTextPropertyToTextList, |
| 54 | _Xutf8TextPropertyToTextList, |
| 55 | _XmbTextListToTextProperty, |
| 56 | _XwcTextListToTextProperty, |
| 57 | _Xutf8TextListToTextProperty, |
| 58 | _XwcFreeStringList, |
| 59 | default_string, |
| 60 | NULL((void*)0), |
| 61 | NULL((void*)0) |
| 62 | }, |
| 63 | { |
| 64 | NULL((void*)0), |
| 65 | create, |
| 66 | initialize, |
| 67 | destroy, |
| 68 | get_values, |
| 69 | _XlcGetLocaleDataBase |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | XLCdMethods _XlcPublicMethods = (XLCdMethods) &publicMethods; |
| 74 | |
| 75 | static XLCd |
| 76 | create( |
| 77 | const char *name, |
| 78 | XLCdMethods methods) |
| 79 | { |
| 80 | XLCd lcd; |
| 81 | XLCdPublicMethods new; |
| 82 | |
| 83 | lcd = Xcalloc(1, sizeof(XLCdRec))calloc(((1) == 0 ? 1 : (1)), (sizeof(XLCdRec))); |
| 84 | if (lcd == NULL((void*)0)) |
| 85 | return (XLCd) NULL((void*)0); |
| 86 | |
| 87 | lcd->core = Xcalloc(1, sizeof(XLCdPublicRec))calloc(((1) == 0 ? 1 : (1)), (sizeof(XLCdPublicRec))); |
Result of 'calloc' is converted to a pointer of type 'struct XLCdCoreRec', which is incompatible with sizeof operand type 'XLCdPublicRec' | |
| 88 | if (lcd->core == NULL((void*)0)) |
| 89 | goto err; |
| 90 | |
| 91 | new = Xmalloc(sizeof(XLCdPublicMethodsRec))malloc(((sizeof(XLCdPublicMethodsRec)) == 0 ? 1 : (sizeof(XLCdPublicMethodsRec )))); |
| 92 | if (new == NULL((void*)0)) |
| 93 | goto err; |
| 94 | memcpy(new,methods,sizeof(XLCdPublicMethodsRec))__builtin___memcpy_chk (new, methods, sizeof(XLCdPublicMethodsRec ), __builtin_object_size (new, 0)); |
| 95 | lcd->methods = (XLCdMethods) new; |
| 96 | |
| 97 | return lcd; |
| 98 | |
| 99 | err: |
| 100 | Xfree(lcd)free((lcd)); |
| 101 | return (XLCd) NULL((void*)0); |
| 102 | } |
| 103 | |
| 104 | static Boolint |
| 105 | load_public( |
| 106 | XLCd lcd) |
| 107 | { |
| 108 | XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd)(&(((XLCdPublic) lcd->core)->pub)); |
| 109 | char **values; |
| 110 | const char *str; |
| 111 | int num; |
| 112 | |
| 113 | if(_XlcCreateLocaleDataBase(lcd) == NULL((void*)0)) |
| 114 | return False0; |
| 115 | |
| 116 | _XlcGetResource(lcd, "XLC_XLOCALE", "mb_cur_max", &values, &num); |
| 117 | if (num > 0) { |
| 118 | pub->mb_cur_max = atoi(values[0]); |
| 119 | if (pub->mb_cur_max < 1) |
| 120 | pub->mb_cur_max = 1; |
| 121 | } else |
| 122 | pub->mb_cur_max = 1; |
| 123 | |
| 124 | _XlcGetResource(lcd, "XLC_XLOCALE", "state_depend_encoding", &values, &num); |
| 125 | if (num > 0 && !_XlcCompareISOLatin1(values[0], "True")) |
| 126 | pub->is_state_depend = True1; |
| 127 | else |
| 128 | pub->is_state_depend = False0; |
| 129 | |
| 130 | _XlcGetResource(lcd, "XLC_XLOCALE", "encoding_name", &values, &num); |
| 131 | str = (num > 0) ? values[0] : "STRING"; |
| 132 | pub->encoding_name = strdup(str); |
| 133 | if (pub->encoding_name == NULL((void*)0)) |
| 134 | return False0; |
| 135 | |
| 136 | return True1; |
| 137 | } |
| 138 | |
| 139 | static Boolint |
| 140 | initialize_core( |
| 141 | XLCd lcd) |
| 142 | { |
| 143 | XLCdMethods methods = lcd->methods; |
| 144 | XLCdMethods core = &publicMethods.core; |
| 145 | |
| 146 | if (methods->close == NULL((void*)0)) |
| 147 | methods->close = core->close; |
| 148 | |
| 149 | if (methods->map_modifiers == NULL((void*)0)) |
| 150 | methods->map_modifiers = core->map_modifiers; |
| 151 | |
| 152 | if (methods->open_om == NULL((void*)0)) |
| 153 | #ifdef USE_DYNAMIC_LC |
| 154 | _XInitDefaultOM(lcd); |
| 155 | #else |
| 156 | _XInitOM(lcd); |
| 157 | #endif |
| 158 | |
| 159 | if (methods->open_im == NULL((void*)0)) |
| 160 | #ifdef USE_DYNAMIC_LC |
| 161 | _XInitDefaultIM(lcd); |
| 162 | #else |
| 163 | _XInitIM(lcd); |
| 164 | #endif |
| 165 | |
| 166 | if (methods->init_parse_info == NULL((void*)0)) |
| 167 | methods->init_parse_info = core->init_parse_info; |
| 168 | |
| 169 | if (methods->mb_text_prop_to_list == NULL((void*)0)) |
| 170 | methods->mb_text_prop_to_list = core->mb_text_prop_to_list; |
| 171 | |
| 172 | if (methods->wc_text_prop_to_list == NULL((void*)0)) |
| 173 | methods->wc_text_prop_to_list = core->wc_text_prop_to_list; |
| 174 | |
| 175 | if (methods->utf8_text_prop_to_list == NULL((void*)0)) |
| 176 | methods->utf8_text_prop_to_list = core->utf8_text_prop_to_list; |
| 177 | |
| 178 | if (methods->mb_text_list_to_prop == NULL((void*)0)) |
| 179 | methods->mb_text_list_to_prop = core->mb_text_list_to_prop; |
| 180 | |
| 181 | if (methods->wc_text_list_to_prop == NULL((void*)0)) |
| 182 | methods->wc_text_list_to_prop = core->wc_text_list_to_prop; |
| 183 | |
| 184 | if (methods->utf8_text_list_to_prop == NULL((void*)0)) |
| 185 | methods->utf8_text_list_to_prop = core->utf8_text_list_to_prop; |
| 186 | |
| 187 | if (methods->wc_free_string_list == NULL((void*)0)) |
| 188 | methods->wc_free_string_list = core->wc_free_string_list; |
| 189 | |
| 190 | if (methods->default_string == NULL((void*)0)) |
| 191 | methods->default_string = core->default_string; |
| 192 | |
| 193 | return True1; |
| 194 | } |
| 195 | |
| 196 | static Boolint |
| 197 | initialize( |
| 198 | XLCd lcd) |
| 199 | { |
| 200 | XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd)(&(((XLCdPublicMethods) lcd->methods)->pub)); |
| 201 | XLCdPublicMethodsPart *pub_methods = &publicMethods.pub; |
| 202 | XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd)(&(((XLCdPublic) lcd->core)->pub)); |
| 203 | char *name; |
| 204 | #if !defined(X_LOCALE) |
| 205 | int len; |
| 206 | char sinamebuf[256]; |
| 207 | char* siname; |
| 208 | #endif |
| 209 | |
| 210 | _XlcInitCTInfo(); |
| 211 | |
| 212 | if (initialize_core(lcd) == False0) |
| 213 | return False0; |
| 214 | |
| 215 | name = lcd->core->name; |
| 216 | #if !defined(X_LOCALE) |
| 217 | /* |
| 218 | * _XlMapOSLocaleName will return the same string or a substring |
| 219 | * of name, so strlen(name) is okay |
| 220 | */ |
| 221 | if ((len = strlen(name)) < sizeof sinamebuf) |
| 222 | siname = sinamebuf; |
| 223 | else |
| 224 | siname = Xmalloc (len + 1)malloc(((len + 1) == 0 ? 1 : (len + 1))); |
| 225 | if (siname == NULL((void*)0)) |
| 226 | return False0; |
| 227 | name = _XlcMapOSLocaleName(name, siname); |
| 228 | #endif |
| 229 | /* _XlcResolveLocaleName will lookup the SI's name for the locale */ |
| 230 | if (_XlcResolveLocaleName(name, pub) == 0) { |
| 231 | #if !defined(X_LOCALE) |
| 232 | if (siname != sinamebuf) Xfree (siname)free((siname)); |
| 233 | #endif |
| 234 | return False0; |
| 235 | } |
| 236 | #if !defined(X_LOCALE) |
| 237 | if (siname != sinamebuf) |
| 238 | Xfree (siname)free((siname)); |
| 239 | #endif |
| 240 | |
| 241 | if (pub->default_string == NULL((void*)0)) |
| 242 | pub->default_string = ""; |
| 243 | |
| 244 | if (methods->get_values == NULL((void*)0)) |
| 245 | methods->get_values = pub_methods->get_values; |
| 246 | |
| 247 | if (methods->get_resource == NULL((void*)0)) |
| 248 | methods->get_resource = pub_methods->get_resource; |
| 249 | |
| 250 | return load_public(lcd); |
| 251 | } |
| 252 | |
| 253 | static void |
| 254 | destroy_core( |
| 255 | XLCd lcd) |
| 256 | { |
| 257 | if (lcd) { |
| 258 | if (lcd->core) { |
| 259 | Xfree(lcd->core->name)free((lcd->core->name)); |
| 260 | Xfree(lcd->core)free((lcd->core)); |
| 261 | } |
| 262 | Xfree(lcd->methods)free((lcd->methods)); |
| 263 | Xfree(lcd)free((lcd)); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | static void |
| 268 | destroy( |
| 269 | XLCd lcd) |
| 270 | { |
| 271 | XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd)(&(((XLCdPublic) lcd->core)->pub)); |
| 272 | |
| 273 | _XlcDestroyLocaleDataBase(lcd); |
| 274 | |
| 275 | Xfree(pub->siname)free((pub->siname)); |
| 276 | Xfree(pub->encoding_name)free((pub->encoding_name)); |
| 277 | |
| 278 | destroy_core(lcd); |
| 279 | } |
| 280 | |
| 281 | static XlcResource resources[] = { |
| 282 | { XlcNCodeset"codeset", NULLQUARK((XrmQuark) 0), sizeof(char *), |
| 283 | XOffsetOf(XLCdPublicRec, pub.codeset)__builtin_offsetof(XLCdPublicRec, pub.codeset), XlcGetMask(1L<<2) }, |
| 284 | { XlcNDefaultString"defaultString", NULLQUARK((XrmQuark) 0), sizeof(char *), |
| 285 | XOffsetOf(XLCdPublicRec, pub.default_string)__builtin_offsetof(XLCdPublicRec, pub.default_string), XlcGetMask(1L<<2) }, |
| 286 | { XlcNEncodingName"encodingName", NULLQUARK((XrmQuark) 0), sizeof(char *), |
| 287 | XOffsetOf(XLCdPublicRec, pub.encoding_name)__builtin_offsetof(XLCdPublicRec, pub.encoding_name), XlcGetMask(1L<<2) }, |
| 288 | { XlcNLanguage"language", NULLQUARK((XrmQuark) 0), sizeof(char *), |
| 289 | XOffsetOf(XLCdPublicRec, pub.language)__builtin_offsetof(XLCdPublicRec, pub.language), XlcGetMask(1L<<2) }, |
| 290 | { XlcNMbCurMax"mbCurMax", NULLQUARK((XrmQuark) 0), sizeof(int), |
| 291 | XOffsetOf(XLCdPublicRec, pub.mb_cur_max)__builtin_offsetof(XLCdPublicRec, pub.mb_cur_max), XlcGetMask(1L<<2) }, |
| 292 | { XlcNStateDependentEncoding"stateDependentEncoding", NULLQUARK((XrmQuark) 0), sizeof(Boolint), |
| 293 | XOffsetOf(XLCdPublicRec, pub.is_state_depend)__builtin_offsetof(XLCdPublicRec, pub.is_state_depend), XlcGetMask(1L<<2) }, |
| 294 | { XlcNTerritory"territory", NULLQUARK((XrmQuark) 0), sizeof(char *), |
| 295 | XOffsetOf(XLCdPublicRec, pub.territory)__builtin_offsetof(XLCdPublicRec, pub.territory), XlcGetMask(1L<<2) } |
| 296 | }; |
| 297 | |
| 298 | static char * |
| 299 | get_values( |
| 300 | XLCd lcd, |
| 301 | XlcArgList args, |
| 302 | int num_args) |
| 303 | { |
| 304 | XLCdPublic pub = (XLCdPublic) lcd->core; |
| 305 | |
| 306 | if (resources[0].xrm_name == NULLQUARK((XrmQuark) 0)) |
| 307 | _XlcCompileResourceList(resources, XlcNumber(resources)(sizeof(resources) / sizeof(resources[0]))); |
| 308 | |
| 309 | return _XlcGetValues((XPointer) pub, resources, XlcNumber(resources)(sizeof(resources) / sizeof(resources[0])), args, |
| 310 | num_args, XlcGetMask(1L<<2)); |
| 311 | } |