diff options
author | Carsten Haitzler <raster@rasterman.com> | 2004-03-30 09:35:50 +0000 |
---|---|---|
committer | Carsten Haitzler <raster@rasterman.com> | 2004-03-30 09:35:50 +0000 |
commit | 14ab26edd47a7b4732c379897024a0c890523960 (patch) | |
tree | a2b84cb2d302bfe0128b78142cc58f0b40d1abd9 /legacy/embryo/src/lib/embryo_str.c | |
parent | f7b3fcbf3a371ea5024ec4c911c061386855e169 (diff) |
fix str... snprintf... oops
SVN revision: 9525
Diffstat (limited to '')
-rw-r--r-- | legacy/embryo/src/lib/embryo_str.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/legacy/embryo/src/lib/embryo_str.c b/legacy/embryo/src/lib/embryo_str.c index 51250a24c6..d1c5b23081 100644 --- a/legacy/embryo/src/lib/embryo_str.c +++ b/legacy/embryo/src/lib/embryo_str.c | |||
@@ -257,7 +257,7 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params) | |||
257 | if (!s2) return -1; | 257 | if (!s2) return -1; |
258 | s2[0] = 0; | 258 | s2[0] = 0; |
259 | pnum = (params[0] / sizeof(Embryo_Cell)) - 3; | 259 | pnum = (params[0] / sizeof(Embryo_Cell)) - 3; |
260 | for (p = 0, o = 0; (s1[i]) && (o < (params[2] - 1)) && (p < pnum); i++) | 260 | for (p = 0, o = 0, i = 0; (s1[i]) && (o < (params[2] - 1)) && (p < (pnum + 1)); i++) |
261 | { | 261 | { |
262 | if ((!inesc) && (!insub)) | 262 | if ((!inesc) && (!insub)) |
263 | { | 263 | { |
@@ -271,6 +271,8 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params) | |||
271 | } | 271 | } |
272 | else | 272 | else |
273 | { | 273 | { |
274 | Embryo_Cell *cptr; | ||
275 | |||
274 | if (inesc) | 276 | if (inesc) |
275 | { | 277 | { |
276 | switch (s1[i]) | 278 | switch (s1[i]) |
@@ -290,7 +292,7 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params) | |||
290 | } | 292 | } |
291 | inesc = 0; | 293 | inesc = 0; |
292 | } | 294 | } |
293 | if (insub) | 295 | if ((insub) && (p < pnum)) |
294 | { | 296 | { |
295 | switch (s1[i]) | 297 | switch (s1[i]) |
296 | { | 298 | { |
@@ -299,7 +301,8 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params) | |||
299 | o++; | 301 | o++; |
300 | break; | 302 | break; |
301 | case 'c': | 303 | case 'c': |
302 | s2[o] = params[4 + p]; | 304 | cptr = embryo_data_address_get(ep, params[4 + p]); |
305 | if (cptr) s2[o] = (char)(*cptr); | ||
303 | p++; | 306 | p++; |
304 | o++; | 307 | o++; |
305 | break; | 308 | break; |
@@ -316,7 +319,8 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params) | |||
316 | else if (s1[i] == 'd') strcpy(fmt, "%d"); | 319 | else if (s1[i] == 'd') strcpy(fmt, "%d"); |
317 | else if (s1[i] == 'x') strcpy(fmt, "%x"); | 320 | else if (s1[i] == 'x') strcpy(fmt, "%x"); |
318 | else if (s1[i] == 'X') strcpy(fmt, "%08x"); | 321 | else if (s1[i] == 'X') strcpy(fmt, "%08x"); |
319 | snprintf(tmp, sizeof(tmp), fmt, params[4 + p]); | 322 | cptr = embryo_data_address_get(ep, params[4 + p]); |
323 | if (cptr) snprintf(tmp, sizeof(tmp), fmt, (int)(*cptr)); | ||
320 | l = strlen(tmp); | 324 | l = strlen(tmp); |
321 | if ((o + l) > (params[2] - 1)) | 325 | if ((o + l) > (params[2] - 1)) |
322 | { | 326 | { |
@@ -324,7 +328,7 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params) | |||
324 | if (l < 0) l = 0; | 328 | if (l < 0) l = 0; |
325 | tmp[l] = 0; | 329 | tmp[l] = 0; |
326 | } | 330 | } |
327 | strcat(s2, tmp); | 331 | strcpy(s2 + o, tmp); |
328 | o += l; | 332 | o += l; |
329 | p++; | 333 | p++; |
330 | } | 334 | } |
@@ -334,7 +338,8 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params) | |||
334 | char tmp[256] = ""; | 338 | char tmp[256] = ""; |
335 | int l; | 339 | int l; |
336 | 340 | ||
337 | snprintf(tmp, sizeof(tmp), "%f", EMBRYO_CELL_TO_FLOAT(params[4 + p])); | 341 | cptr = embryo_data_address_get(ep, params[4 + p]); |
342 | if (cptr) snprintf(tmp, sizeof(tmp), "%f", (double)EMBRYO_CELL_TO_FLOAT(*cptr)); | ||
338 | l = strlen(tmp); | 343 | l = strlen(tmp); |
339 | if ((o + l) > (params[2] - 1)) | 344 | if ((o + l) > (params[2] - 1)) |
340 | { | 345 | { |
@@ -342,7 +347,7 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params) | |||
342 | if (l < 0) l = 0; | 347 | if (l < 0) l = 0; |
343 | tmp[l] = 0; | 348 | tmp[l] = 0; |
344 | } | 349 | } |
345 | strcat(s2, tmp); | 350 | strcpy(s2 + o, tmp); |
346 | o += l; | 351 | o += l; |
347 | p++; | 352 | p++; |
348 | } | 353 | } |
@@ -360,7 +365,7 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params) | |||
360 | if (l < 0) l = 0; | 365 | if (l < 0) l = 0; |
361 | tmp[l] = 0; | 366 | tmp[l] = 0; |
362 | } | 367 | } |
363 | strcat(s2, tmp); | 368 | strcpy(s2 + o, tmp); |
364 | o += l; | 369 | o += l; |
365 | p++; | 370 | p++; |
366 | } | 371 | } |
@@ -370,6 +375,8 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params) | |||
370 | } | 375 | } |
371 | insub = 0; | 376 | insub = 0; |
372 | } | 377 | } |
378 | else if (insub) | ||
379 | insub = 0; | ||
373 | } | 380 | } |
374 | } | 381 | } |
375 | s2[o] = 0; | 382 | s2[o] = 0; |