(/home/sate/Testcases/c/cve/wireshark-1.2.0/gtk/sctp_byte_graph_dlg.c) |
| |
| 263 | | | static void sctp_graph_draw(struct sctp_udata *u_data) |
| 264 | | | { |
| 265 | | | int length, lwidth; |
| 266 | | | guint32 distance=5, i, e, sec, w, start, a, j, b; |
| 267 | | | gint label_width, label_height; |
| 268 | | | char label_string[15]; |
| 269 | | | gfloat dis; |
| 270 | | | gboolean write_label = FALSE; |
| 271 | | | PangoLayout *layout; |
| 272 | | | |
| 273 | | | if (u_data->io->x1_tmp_sec == 0 && u_data->io->x1_tmp_usec == 0) |
| 274 | | | u_data->io->offset = 0; |
| 275 | | | else |
| 276 | | | u_data->io->offset = 5; |
| 277 | | | |
| 278 | | | if (u_data->io->x2_tmp_sec - u_data->io->x1_tmp_sec > 1500) |
| 279 | | | { |
| 280 | | | u_data->io->min_x=u_data->io->x1_tmp_sec; |
| 281 | | | u_data->io->max_x=u_data->io->x2_tmp_sec; |
| 282 | | | u_data->io->uoff = TRUE; |
| 283 | | | } |
| 284 | | | else |
| 285 | | | { |
| 286 | | | u_data->io->min_x=((guint32) (u_data->io->x1_tmp_sec*1000000.0))+u_data->io->x1_tmp_usec; |
| 287 | | | u_data->io->max_x=((guint32) (u_data->io->x2_tmp_sec*1000000.0))+u_data->io->x2_tmp_usec; |
| 288 | | | u_data->io->uoff = FALSE; |
| 289 | | | } |
| 290 | | | |
| 291 | | | u_data->io->tmp_width = u_data->io->max_x - u_data->io->min_x; |
| 292 | | | |
| 293 | | | if (u_data->dir == 1) |
| 294 | | | { |
| 295 | | | if (u_data->io->tmp == FALSE) |
| 296 | | | { |
| 297 | | | if (u_data->assoc->sort_tsn1 != NULL) |
| 298 | | | u_data->io->max_y = u_data->io->tmp_max_tsn1 - u_data->io->tmp_min_tsn1; |
| 299 | | | else |
| 300 | | | u_data->io->max_y = 0; |
| 301 | | | u_data->io->min_y = 0; |
| 302 | | | } |
| 303 | | | else |
| 304 | | | { |
| 305 | | | u_data->io->max_y = u_data->io->tmp_max_tsn1; |
| 306 | | | u_data->io->min_y = u_data->io->tmp_min_tsn1; |
| 307 | | | } |
| 308 | | | } |
| 309 | | | else if (u_data->dir == 2) |
| 310 | | | { |
| 311 | | | if (u_data->io->tmp == FALSE) |
| 312 | | | { |
| 313 | | | if (u_data->assoc->tsn2 != NULL) |
| 314 | | | u_data->io->max_y = u_data->io->tmp_max_tsn2 - u_data->io->tmp_min_tsn2; |
| 315 | | | else |
| 316 | | | u_data->io->max_y = 0; |
| 317 | | | u_data->io->min_y = 0; |
| 318 | | | } |
| 319 | | | else |
| 320 | | | { |
| 321 | | | u_data->io->max_y = u_data->io->tmp_max_tsn2; |
| 322 | | | u_data->io->min_y = u_data->io->tmp_min_tsn2; |
| 323 | | | } |
| 324 | | | } |
| 325 | | | gdk_draw_rectangle(u_data->io->pixmap, u_data->io->draw_area->style->white_gc, |
| 326 | | | TRUE, 0, 0, u_data->io->draw_area->allocation.width, |
| 327 | | | u_data->io->draw_area->allocation.height); |
| 328 | | | |
| 329 | | | distance = 5; |
Useless Assignment
This code assigns the variable the same value it already had. |
|
| 330 | | | |
| 331 | | | gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, |
| 332 | | | LEFT_BORDER+u_data->io->offset,u_data->io->pixmap_height - BOTTOM_BORDER, |
| 333 | | | u_data->io->pixmap_width - RIGHT_BORDER + u_data->io->offset, u_data->io->pixmap_height - BOTTOM_BORDER); |
| 334 | | | gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, |
| 335 | | | u_data->io->pixmap_width - RIGHT_BORDER + u_data->io->offset, u_data->io->pixmap_height - BOTTOM_BORDER, u_data->io->pixmap_width - RIGHT_BORDER + u_data->io->offset - 5, u_data->io->pixmap_height - BOTTOM_BORDER - 5); |
| 336 | | | gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, |
| 337 | | | u_data->io->pixmap_width - RIGHT_BORDER + u_data->io->offset, u_data->io->pixmap_height - BOTTOM_BORDER, u_data->io->pixmap_width - RIGHT_BORDER + u_data->io->offset - 5, u_data->io->pixmap_height - BOTTOM_BORDER + 5); |
| 338 | | | u_data->io->axis_width = u_data->io->pixmap_width - LEFT_BORDER - RIGHT_BORDER - u_data->io->offset; |
| 339 | | | |
| 340 | | | if(u_data->io->tmp_width>0){ |
| 341 | | | u_data->io->x_interval = (float)((u_data->io->axis_width*1.0)/u_data->io->tmp_width); |
| 342 | | | } else { |
| 343 | | | u_data->io->x_interval = (float)(u_data->io->axis_width); |
| 344 | | | } |
| 345 | | | |
| 346 | | | e=0; |
| 347 | | | if (u_data->io->x_interval < 1) |
| 348 | | | { |
| 349 | | | dis = 1 / u_data->io->x_interval; |
| 350 | | | while (dis >1) |
| 351 | | | { |
| 352 | | | dis /= 10; |
| 353 | | | e++; |
| 354 | | | } |
| 355 | | | distance = 1; |
| 356 | | | for (i=0; i<=e+1; i++) |
| 357 | | | distance *= 10; |
| 358 | | | } |
| 359 | | | else |
| 360 | | | distance = 5; |
| 361 | | | |
| 362 | | | g_snprintf(label_string, sizeof(label_string), "%d", 0); |
| 363 | | | memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15); |
| 364 | | | layout = gtk_widget_create_pango_layout(u_data->io->draw_area, label_string); |
| 365 | | | pango_layout_get_pixel_size(layout, &label_width, &label_height); |
| 366 | | | |
| 367 | | | if (u_data->io->x1_tmp_usec == 0) |
| 368 | | | sec = u_data->io->x1_tmp_sec; |
| 369 | | | else |
| 370 | | | sec = u_data->io->x1_tmp_sec+1; |
| 371 | | | |
| 372 | | | if (u_data->io->offset != 0) |
| 373 | | | { |
| 374 | | | g_snprintf(label_string, sizeof(label_string), "%u", u_data->io->x1_tmp_sec); |
| 375 | | | memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string)); |
| 376 | | | pango_layout_set_text(layout, label_string, -1); |
| 377 | | | pango_layout_get_pixel_size(layout, &lwidth, NULL); |
| 378 | | | |
| 379 | | | gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, |
| 380 | | | LEFT_BORDER - 25, |
| 381 | | | u_data->io->pixmap_height - BOTTOM_BORDER + 20, |
| 382 | | | layout); |
| 383 | | | } |
| 384 | | | w = (guint32)(500 / (guint32)(distance * u_data->io->x_interval)); |
| 385 | | | if (w == 0) |
| 386 | | | w = 1; |
| 387 | | | if (w == 4 || w==3 || w==2) |
| 388 | | | { |
| 389 | | | w = 5; |
| 390 | | | a = distance / 10; |
| 391 | | | b = (guint32)((u_data->io->min_x/100000))%10; |
| 392 | | | } |
| 393 | | | else |
| 394 | | | { |
| 395 | | | a = distance / 5; |
| 396 | | | b = 0; |
| 397 | | | } |
| 398 | | | |
| 399 | | | if (!u_data->io->uoff) |
| 400 | | | { |
| 401 | | | if (a>=1000000) |
| 402 | | | { |
| 403 | | | start=u_data->io->min_x/1000000*1000000; |
| 404 | | | if (a==1000000) |
| 405 | | | b = 0; |
| 406 | | | } |
| 407 | | | else |
| 408 | | | { |
| 409 | | | start=u_data->io->min_x/100000; |
| 410 | | | if (start%2!=0) |
| 411 | | | start--; |
| 412 | | | start*=100000; |
| 413 | | | b = (guint32)((start/100000))%10; |
| 414 | | | } |
| 415 | | | } |
| 416 | | | else |
| 417 | | | { |
| 418 | | | start = u_data->io->min_x; |
| 419 | | | if (start%2!=0) |
| 420 | | | start--; |
| 421 | | | b = 0; |
| 422 | | | |
| 423 | | | } |
| 424 | | | |
| 425 | | | for (i=start, j=b; i<=u_data->io->max_x; i+=a, j++) |
| 426 | | | { |
| 427 | | | if (!u_data->io->uoff) |
| 428 | | | if (i >= u_data->io->min_x && i % 1000000 != 0) |
| 429 | | | { |
| 430 | | | length = 5; |
| 431 | | | g_snprintf(label_string, sizeof(label_string), "%d", i%1000000); |
| 432 | | | |
| 433 | | | if (j % w == 0) |
| 434 | | | { |
| 435 | | | length = 10; |
| 436 | | | |
| 437 | | | memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string)); |
| 438 | | | pango_layout_set_text(layout, label_string, -1); |
| 439 | | | pango_layout_get_pixel_size(layout, &lwidth, NULL); |
| 440 | | | gdk_draw_layout(u_data->io->pixmap, |
| 441 | | | u_data->io->draw_area->style->black_gc, |
| 442 | | | (guint32)(LEFT_BORDER + u_data->io->offset + (i - u_data->io->min_x) * u_data->io->x_interval - lwidth / 2), |
| 443 | | | u_data->io->pixmap_height - BOTTOM_BORDER + 10, |
| 444 | | | layout); |
| 445 | | | } |
| 446 | | | gdk_draw_line(u_data->io->pixmap, |
| 447 | | | u_data->io->draw_area->style->black_gc, |
| 448 | | | (guint32)(LEFT_BORDER + u_data->io->offset + (i - u_data->io->min_x) * u_data->io->x_interval), |
| 449 | | | u_data->io->pixmap_height - BOTTOM_BORDER, |
| 450 | | | (guint32)(LEFT_BORDER + u_data->io->offset + (i - u_data->io->min_x) * u_data->io->x_interval), |
| 451 | | | u_data->io->pixmap_height - BOTTOM_BORDER + length); |
| 452 | | | } |
| 453 | | | |
| 454 | | | if (!u_data->io->uoff) |
| 455 | | | { |
| 456 | | | if (i%1000000==0 && j%w==0) |
| 457 | | | { |
| 458 | | | sec=i/1000000; |
| 459 | | | write_label = TRUE; |
| 460 | | | } |
| 461 | | | } |
| 462 | | | else |
| 463 | | | { |
| 464 | | | if (j%w == 0) |
| 465 | | | { |
| 466 | | | sec = i; |
| 467 | | | write_label = TRUE; |
| 468 | | | } |
| 469 | | | } |
| 470 | | | if (write_label) |
| 471 | | | { |
| 472 | | | gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, |
| 473 | | | (guint32)(LEFT_BORDER + u_data->io->offset + (i - u_data->io->min_x) * u_data->io->x_interval), |
| 474 | | | u_data->io->pixmap_height - BOTTOM_BORDER, |
| 475 | | | (guint32)(LEFT_BORDER + u_data->io->offset + (i - u_data->io->min_x) * u_data->io->x_interval), |
| 476 | | | u_data->io->pixmap_height - BOTTOM_BORDER + 10); |
| 477 | | | |
| 478 | | | g_snprintf(label_string, sizeof(label_string), "%d", sec); |
| 479 | | | memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string)); |
| 480 | | | pango_layout_set_text(layout, label_string, -1); |
| 481 | | | pango_layout_get_pixel_size(layout, &lwidth, NULL); |
| 482 | | | gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, |
| 483 | | | (guint32)(LEFT_BORDER + u_data->io->offset + (i - u_data->io->min_x) * u_data->io->x_interval-10), |
| 484 | | | u_data->io->pixmap_height - BOTTOM_BORDER + 20, |
| 485 | | | layout); |
| 486 | | | write_label = FALSE; |
| 487 | | | } |
| 488 | | | } |
| 489 | | | |
| 490 | | | g_strlcpy(label_string, "sec", sizeof(label_string)); |
| 491 | | | |
| 492 | | | memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string)); |
| 493 | | | pango_layout_set_text(layout, label_string, -1); |
| 494 | | | pango_layout_get_pixel_size(layout, &lwidth, NULL); |
| 495 | | | gdk_draw_layout(u_data->io->pixmap, |
| 496 | | | u_data->io->draw_area->style->black_gc, |
| 497 | | | u_data->io->pixmap_width - RIGHT_BORDER - 10, |
| 498 | | | u_data->io->pixmap_height - BOTTOM_BORDER + 30, |
| 499 | | | layout); |
| 500 | | | distance = 5; |
| 501 | | | |
| 502 | | | |
| 503 | | | gdk_draw_line(u_data->io->pixmap, |
| 504 | | | u_data->io->draw_area->style->black_gc, |
| 505 | | | LEFT_BORDER,TOP_BORDER - u_data->io->offset, |
| 506 | | | LEFT_BORDER, |
| 507 | | | u_data->io->pixmap_height - BOTTOM_BORDER - u_data->io->offset); |
| 508 | | | gdk_draw_line(u_data->io->pixmap, |
| 509 | | | u_data->io->draw_area->style->black_gc, |
| 510 | | | LEFT_BORDER, |
| 511 | | | TOP_BORDER - u_data->io->offset, |
| 512 | | | LEFT_BORDER - 5, |
| 513 | | | TOP_BORDER - u_data->io->offset + 5); |
| 514 | | | gdk_draw_line(u_data->io->pixmap, |
| 515 | | | u_data->io->draw_area->style->black_gc, |
| 516 | | | LEFT_BORDER, |
| 517 | | | TOP_BORDER - u_data->io->offset, |
| 518 | | | LEFT_BORDER + 5, |
| 519 | | | TOP_BORDER - u_data->io->offset + 5); |
| 520 | | | |
| 521 | | | u_data->io->y_interval = (float)(((u_data->io->pixmap_height - TOP_BORDER - BOTTOM_BORDER) * 1.0)/(u_data->io->max_y - u_data->io->min_y)); |
| 522 | | | |
| 523 | | | e = 0; |
| 524 | | | if (u_data->io->y_interval < 1) |
| 525 | | | { |
| 526 | | | dis = 1 / u_data->io->y_interval; |
| 527 | | | while (dis > 1) |
| 528 | | | { |
| 529 | | | dis /= 10; |
| 530 | | | e++; |
| 531 | | | } |
| 532 | | | distance = 1; |
| 533 | | | for (i=0; i<=e; i++) |
| 534 | | | distance = distance * 10; |
| 535 | | | } |
| 536 | | | else if (u_data->io->y_interval<2) |
| 537 | | | distance = 10; |
| 538 | | | |
| 539 | | | if (u_data->io->max_y > 0) |
| 540 | | | { |
| 541 | | | for (i=u_data->io->min_y/distance*distance; i<=u_data->io->max_y; i+=distance/5) |
| 542 | | | { |
| 543 | | | if (i >= u_data->io->min_y) |
| 544 | | | { |
| 545 | | | length = 5; |
| 546 | | | g_snprintf(label_string, sizeof(label_string), "%d", i); |
| 547 | | | |
| 548 | | | if (i%distance == 0 || (distance <= 5 && u_data->io->y_interval > 10)) |
| 549 | | | { |
| 550 | | | length = 10; |
| 551 | | | |
| 552 | | | memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string)); |
| 553 | | | pango_layout_set_text(layout, label_string, -1); |
| 554 | | | pango_layout_get_pixel_size(layout, &lwidth, NULL); |
| 555 | | | gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, |
| 556 | | | LEFT_BORDER - length - lwidth - 5, |
| 557 | | | (guint32)(u_data->io->pixmap_height - BOTTOM_BORDER - u_data->io->offset - (i - u_data->io->min_y) * u_data->io->y_interval - 3), |
| 558 | | | layout); |
| 559 | | | } |
| 560 | | | gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, |
| 561 | | | LEFT_BORDER - length, |
| 562 | | | (guint32)(u_data->io->pixmap_height - BOTTOM_BORDER - u_data->io->offset - (i - u_data->io->min_y) * u_data->io->y_interval), |
| 563 | | | LEFT_BORDER, |
| 564 | | | (guint32)(u_data->io->pixmap_height - BOTTOM_BORDER - u_data->io->offset - (i - u_data->io->min_y) * u_data->io->y_interval)); |
| 565 | | | } |
| 566 | | | } |
| 567 | | | } |
| 568 | | | else |
| 569 | | | simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "No Data Chunks sent"); |
| 570 | | | } |
| |