Print this page
10118 libeti() NULL check after deref
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libeti/form/common/field.c
+++ new/usr/src/lib/libeti/form/common/field.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
21 21 */
22 22 /* Copyright (c) 1988 AT&T */
23 23 /* All Rights Reserved */
24 24
25 25
26 26 /*
27 27 * Copyright (c) 1997, by Sun Microsystems, Inc.
28 28 * All rights reserved.
29 29 */
30 30
31 -#pragma ident "%Z%%M% %I% %E% SMI"
31 +/*
32 + * Copyright (c) 2018, Joyent, Inc.
33 + */
32 34
33 35 /*LINTLIBRARY*/
34 36
35 37 #include <sys/types.h>
36 38 #include <stdlib.h>
37 39 #include "utility.h"
38 40
39 41 /*
40 42 * default field
41 43 */
42 44
43 45 static FIELD default_field =
44 46 {
45 47 0, /* status */
46 48 0, /* rows */
47 49 0, /* cols */
48 50 0, /* frow */
49 51 0, /* fcol */
50 52 0, /* drows */
51 53 0, /* dcols */
52 54 0, /* maxgrow */
53 55 0, /* nrow */
54 56 0, /* nbuf */
55 57 NO_JUSTIFICATION, /* just */
56 58 0, /* page */
57 59 0, /* index */
58 60 ' ', /* pad */
59 61 A_NORMAL, /* fore */
60 62 A_NORMAL, /* back */
61 63 O_VISIBLE |
62 64 O_ACTIVE |
63 65 O_PUBLIC |
64 66 O_EDIT |
65 67 O_WRAP |
66 68 O_BLANK |
67 69 O_AUTOSKIP |
68 70 O_NULLOK |
69 71 O_PASSOK |
70 72 O_STATIC, /* opts */
71 73 (FIELD *)0, /* snext */
72 74 (FIELD *)0, /* sprev */
73 75 (FIELD *)0, /* link */
74 76 (FORM *)0, /* form */
75 77 (FIELDTYPE *)0, /* type */
76 78 (char *)0, /* arg */
77 79 (char *)0, /* buf */
78 80 (char *)0, /* usrptr */
79 81 };
80 82
81 83 FIELD * _DEFAULT_FIELD = &default_field;
82 84
83 85 /*
84 86 * MakeType
85 87 */
86 88
87 89 static int
88 90 MakeType(FIELD *f, va_list *ap)
89 91 {
90 92 int err = 0;
91 93
92 94 f->arg = MakeArg(f, ap, &err); /* pick off type specific args */
93 95
94 96 if (err) {
95 97 FreeArg(f); /* release type specific args */
96 98 f->type = (FIELDTYPE *)0;
97 99 f->arg = (char *)0;
98 100 return (FALSE);
99 101 }
100 102 IncrType(f->type); /* increment reference count */
101 103 return (TRUE);
102 104 }
103 105
104 106 /*
105 107 * CopyType
106 108 */
107 109
108 110 static int
109 111 CopyType(FIELD *f, FIELD *fsrc)
110 112 {
111 113 int err = 0;
112 114
113 115 f->type = fsrc->type; /* copy field type */
114 116 f->arg = CopyArg(fsrc, &err); /* copy type specific info */
115 117
116 118 if (err) {
117 119 FreeArg(f); /* release type specific args */
118 120 f->type = (FIELDTYPE *)0;
119 121 f->arg = (char *)0;
120 122 return (FALSE);
121 123 }
122 124 IncrType(f->type); /* increment reference count */
123 125 return (TRUE);
124 126 }
125 127
126 128 /*
127 129 * FreeType
128 130 */
129 131
130 132 static void
131 133 FreeType(FIELD *f)
132 134 {
133 135 DecrType(f->type); /* decrement reference count */
134 136 FreeArg(f); /* release type specific args */
135 137 }
136 138
137 139 /*
138 140 * new_field
139 141 */
140 142
141 143 FIELD *
142 144 new_field(int rows, int cols, int frow, int fcol, int nrow, int nbuf)
143 145
144 146 /* int rows; number of visible rows */
145 147 /* int cols; number of visible cols */
146 148 /* int frow; first row relative to form origin */
147 149 /* int fcol; first col relative to form origin */
148 150 /* int nrow; number of off screen rows */
149 151 /* int nbuf; number of additional buffers */
150 152 {
151 153 FIELD *f = (FIELD *) 0;
152 154 int i, size;
153 155
154 156 if (rows > 0 && cols > 0 && frow >= 0 && fcol >= 0 && nrow >= 0 &&
155 157 nbuf >= 0 && Alloc(f, FIELD)) {
156 158 *f = *_DEFAULT_FIELD;
157 159
158 160 f->rows = rows;
159 161 f->cols = cols;
160 162 f->frow = frow;
161 163 f->fcol = fcol;
162 164 f->drows = rows + nrow;
163 165 f->dcols = cols;
164 166 f->nrow = nrow;
165 167 f->nbuf = nbuf;
166 168 f->link = f;
167 169
168 170 if (CopyType(f, _DEFAULT_FIELD)) {
169 171 size = TotalBuf(f);
170 172
171 173 if (arrayAlloc(Buf(f), size, char)) {
172 174 (void) memset(Buf(f), ' ', size);
173 175
174 176 for (i = 0; i <= f->nbuf; ++i)
175 177 *(Buffer(f, i + 1) - 1) = '\0';
176 178 return (f);
177 179 }
178 180 }
179 181 }
180 182 (void) free_field(f);
181 183 return ((FIELD *) 0);
182 184 }
183 185
184 186 /*
185 187 * dup_field
186 188 */
187 189
188 190 FIELD *
189 191 dup_field(FIELD *field, int frow, int fcol)
190 192
191 193 /* FIELD * field; field to duplicate */
192 194 /* int frow; first row relative to form origin */
193 195 /* int fcol; first col relative to form origin */
194 196 {
195 197 FIELD *f = (FIELD *) 0;
196 198 int size;
197 199
198 200 if (field && frow >= 0 && fcol >= 0 && Alloc(f, FIELD)) {
199 201 *f = *_DEFAULT_FIELD;
200 202
201 203 f->frow = frow;
202 204 f->fcol = fcol;
203 205 f->link = f;
204 206
205 207 f->rows = field->rows;
206 208 f->cols = field->cols;
207 209 f->drows = field->drows;
208 210 f->dcols = field->dcols;
209 211 f->maxgrow = field->maxgrow;
210 212 f->nrow = field->nrow;
211 213 f->nbuf = field->nbuf;
212 214 f->just = field->just;
213 215 f->fore = field->fore;
214 216 f->back = field->back;
215 217 f->pad = field->pad;
216 218 f->opts = field->opts;
217 219 f->usrptr = field->usrptr;
218 220 f->status = Status(field, GROWABLE);
219 221
220 222 if (CopyType(f, field)) {
221 223 size = TotalBuf(f);
222 224
223 225 if (arrayAlloc(Buf(f), size, char)) {
224 226 (void) memcpy(Buf(f), Buf(field), size);
225 227 return (f);
226 228 }
227 229 }
228 230 }
229 231 (void) free_field(f);
230 232 return ((FIELD *) 0);
231 233 }
232 234
233 235 /*
234 236 * link_field
235 237 */
236 238
237 239 FIELD *
238 240 link_field(FIELD *field, int frow, int fcol)
239 241
240 242 /* FIELD * field; field to link to */
241 243 /* int frow; first row relative to form origin */
242 244 /* int fcol; first col relative to form origin */
243 245 {
244 246 FIELD *f = (FIELD *) 0;
245 247
246 248 if (field && frow >= 0 && fcol >= 0 && Alloc(f, FIELD)) {
247 249 *f = *_DEFAULT_FIELD;
248 250
249 251 f->frow = frow;
250 252 f->fcol = fcol;
251 253
252 254 f->link = field->link;
253 255 field->link = f; /* add field to linked list */
254 256
255 257 f->buf = field->buf;
256 258 f->rows = field->rows;
257 259 f->cols = field->cols;
258 260 f->drows = field->drows;
259 261 f->dcols = field->dcols;
260 262 f->maxgrow = field->maxgrow;
261 263 f->nrow = field->nrow;
262 264 f->nbuf = field->nbuf;
263 265 f->just = field->just;
264 266 f->fore = field->fore;
265 267 f->back = field->back;
266 268 f->pad = field->pad;
267 269 f->opts = field->opts;
268 270 f->usrptr = field->usrptr;
269 271 f->status = Status(field, GROWABLE);
270 272
271 273 if (CopyType(f, field))
272 274 return (f);
273 275 }
274 276 (void) free_field(f);
275 277 return ((FIELD *) 0);
276 278 }
277 279
278 280 /*
279 281 * free_field
280 282 */
281 283
282 284 int
283 285 free_field(FIELD *f)
284 286 {
285 287 FIELD *p;
286 288
287 289 if (!f)
288 290 return (E_BAD_ARGUMENT);
289 291
290 292 if (f->form)
291 293 return (E_CONNECTED);
292 294
293 295 if (f->link != f) { /* check for linked field */
294 296 for (p = f->link; p->link != f; p = p->link)
295 297 ;
296 298 p->link = f->link; /* delete from list */
297 299 } else
298 300 Free(Buf(f)); /* free buffer space */
299 301
300 302 FreeType(f);
301 303 Free(f);
302 304 return (E_OK);
303 305 }
304 306
305 307 /*
306 308 * field_info
307 309 */
308 310
309 311 int
310 312 field_info(FIELD *f, int *rows, int *cols, int *frow, int *fcol,
311 313 int *nrow, int *nbuf)
312 314
313 315 /* FIELD *f; field whose information is wanted */
314 316 /* int *rows; number of visible rows */
315 317 /* int *cols; number of visible cols */
316 318 /* int *frow; first row relative to form origin */
317 319 /* int *fcol; first col relative to form origin */
318 320 /* int *nrow; number of off screen rows */
319 321 /* int *nbuf; number of additional buffers */
320 322 {
321 323 if (!f)
322 324 return (E_BAD_ARGUMENT);
323 325
324 326 *rows = f->rows;
325 327 *cols = f->cols;
326 328 *frow = f->frow;
327 329 *fcol = f->fcol;
328 330 *nrow = f->nrow;
329 331 *nbuf = f->nbuf;
↓ open down ↓ |
288 lines elided |
↑ open up ↑ |
330 332 return (E_OK);
331 333 }
332 334
333 335 /*
334 336 * set_max_field
335 337 */
336 338
337 339 int
338 340 set_max_field(FIELD *f, int max)
339 341 {
340 - BOOLEAN onerow = OneRow(f);
342 + BOOLEAN onerow;
341 343
342 - if (!f || max && ((onerow && f->dcols > max) ||
344 + if (!f)
345 + return (E_BAD_ARGUMENT);
346 +
347 + onerow = OneRow(f);
348 +
349 + if (max && ((onerow && f->dcols > max) ||
343 350 (!onerow && f->drows > max)))
344 351 return (E_BAD_ARGUMENT);
345 352
346 353 f->maxgrow = max;
347 354 Clr(f, GROWABLE);
348 355
349 356 if (!Opt(f, O_STATIC) && ((!max || onerow && f->dcols < max) ||
350 357 (!onerow && f->drows < max))) {
351 358 Set(f, GROWABLE);
352 359 }
353 360
354 361 return (E_OK);
355 362 }
356 363
357 364 /*
358 365 * dynamic_field_info
359 366 */
360 367
361 368 int
362 369 dynamic_field_info(FIELD *f, int *drows, int *dcols, int *max)
363 370
364 371 /* FIELD *f; field whose information is wanted */
365 372 /* int *drows; number of actual rows */
366 373 /* int *dcols; number of actual cols */
367 374 /* int *max; maximum growth allowable, else -1 */
368 375 {
369 376 if (!f)
370 377 return (E_BAD_ARGUMENT);
371 378
372 379 *drows = f->drows;
373 380 *dcols = f->dcols;
374 381 *max = f->maxgrow;
375 382 return (E_OK);
376 383 }
377 384
378 385 /*
379 386 * move_field
380 387 */
381 388
382 389 int
383 390 move_field(FIELD *f, int frow, int fcol)
384 391
385 392 /* FIELD *f; field to move */
386 393 /* int frow; first row relative to form origin */
387 394 /* int fcol; first col relative to form origin */
388 395 {
389 396 if (! f || frow < 0 || fcol < 0)
390 397 return (E_BAD_ARGUMENT);
391 398
392 399 if (f->form)
393 400 return (E_CONNECTED);
394 401
395 402 f->frow = frow;
396 403 f->fcol = fcol;
397 404 return (E_OK);
398 405 }
399 406
400 407 /*
401 408 * set_field_type
402 409 */
403 410
404 411 int
405 412 set_field_type(FIELD *f, FIELDTYPE *ft, ...)
406 413 {
407 414 va_list ap;
408 415 int v = E_SYSTEM_ERROR;
409 416
410 417 va_start(ap, ft);
411 418 f = Field(f);
412 419 FreeType(f); /* free old type */
413 420 f->type = ft;
414 421
415 422 if (MakeType(f, &ap)) /* set up new type */
416 423 v = E_OK;
417 424 va_end(ap);
418 425 return (v);
419 426 }
420 427
421 428 FIELDTYPE *
422 429 field_type(FIELD *f)
423 430 {
424 431 return (Field(f)->type);
425 432 }
426 433
427 434 char *
428 435 field_arg(FIELD *f)
429 436 {
430 437 return (Field(f)->arg);
431 438 }
432 439
433 440 /*
434 441 * set_new_page
435 442 */
436 443
437 444 int
438 445 set_new_page(FIELD *f, int flag)
439 446 {
440 447 f = Field(f);
441 448
442 449 if (f->form)
443 450 return (E_CONNECTED);
444 451
445 452 if (flag)
446 453 Set(f, NEW_PAGE);
447 454 else
448 455 Clr(f, NEW_PAGE);
449 456
450 457 return (E_OK);
451 458 }
452 459
453 460 int
454 461 new_page(FIELD *f)
455 462 {
456 463 if (Status(Field(f), NEW_PAGE))
457 464 return (TRUE);
458 465 else
459 466 return (FALSE);
460 467 }
↓ open down ↓ |
108 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX