Mercurial > dwindows
comparison gtk4/dw.c @ 2663:3b3be9f7f452
GTK3/4: Add some memory safety checks that were in GTK2 but missing from GTK 3/4.
Noticed during a prior CID commit. Committing on Windows, so untested..
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 04 Oct 2021 19:26:08 +0000 |
parents | 650f8b062317 |
children | 85917c0c52f1 |
comparison
equal
deleted
inserted
replaced
2662:60df58233244 | 2663:3b3be9f7f452 |
---|---|
539 if(data) | 539 if(data) |
540 { | 540 { |
541 void **params = (void **)data; | 541 void **params = (void **)data; |
542 int counter = GPOINTER_TO_INT(params[0]); | 542 int counter = GPOINTER_TO_INT(params[0]); |
543 GtkWidget *widget = (GtkWidget *)params[2]; | 543 GtkWidget *widget = (GtkWidget *)params[2]; |
544 char text[100]; | 544 char text[101] = {0}; |
545 | 545 |
546 sprintf(text, "_dw_sigwindow%d", counter); | 546 snprintf(text, 100, "_dw_sigwindow%d", counter); |
547 sh.window = (HWND)g_object_get_data(G_OBJECT(widget), text); | 547 sh.window = (HWND)g_object_get_data(G_OBJECT(widget), text); |
548 sprintf(text, "_dw_sigfunc%d", counter); | 548 snprintf(text, 100, "_dw_sigfunc%d", counter); |
549 sh.func = (void *)g_object_get_data(G_OBJECT(widget), text); | 549 sh.func = (void *)g_object_get_data(G_OBJECT(widget), text); |
550 sprintf(text, "_dw_intfunc%d", counter); | 550 snprintf(text, 100, "_dw_intfunc%d", counter); |
551 sh.intfunc = (void *)g_object_get_data(G_OBJECT(widget), text); | 551 sh.intfunc = (void *)g_object_get_data(G_OBJECT(widget), text); |
552 sprintf(text, "_dw_sigdata%d", counter); | 552 snprintf(text, 100, "_dw_sigdata%d", counter); |
553 sh.data = g_object_get_data(G_OBJECT(widget), text); | 553 sh.data = g_object_get_data(G_OBJECT(widget), text); |
554 sprintf(text, "_dw_sigcid%d", counter); | 554 snprintf(text, 100, "_dw_sigcid%d", counter); |
555 sh.cid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), text)); | 555 sh.cid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), text)); |
556 } | 556 } |
557 return sh; | 557 return sh; |
558 } | 558 } |
559 | 559 |
560 static void _dw_remove_signal_handler(GtkWidget *widget, int counter) | 560 static void _dw_remove_signal_handler(GtkWidget *widget, int counter) |
561 { | 561 { |
562 char text[100]; | 562 char text[101] = {0}; |
563 gint cid; | 563 gint cid; |
564 | 564 |
565 sprintf(text, "_dw_sigcid%d", counter); | 565 snprintf(text, 100, "_dw_sigcid%d", counter); |
566 cid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), text)); | 566 cid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), text)); |
567 if(cid > 0) | 567 if(cid > 0) |
568 g_signal_handler_disconnect(G_OBJECT(widget), cid); | 568 g_signal_handler_disconnect(G_OBJECT(widget), cid); |
569 g_object_set_data(G_OBJECT(widget), text, NULL); | 569 g_object_set_data(G_OBJECT(widget), text, NULL); |
570 sprintf(text, "_dw_sigwindow%d", counter); | 570 snprintf(text, 100, "_dw_sigwindow%d", counter); |
571 g_object_set_data(G_OBJECT(widget), text, NULL); | 571 g_object_set_data(G_OBJECT(widget), text, NULL); |
572 sprintf(text, "_dw_sigfunc%d", counter); | 572 snprintf(text, 100, "_dw_sigfunc%d", counter); |
573 g_object_set_data(G_OBJECT(widget), text, NULL); | 573 g_object_set_data(G_OBJECT(widget), text, NULL); |
574 sprintf(text, "_dw_intfunc%d", counter); | 574 snprintf(text, 100, "_dw_intfunc%d", counter); |
575 g_object_set_data(G_OBJECT(widget), text, NULL); | 575 g_object_set_data(G_OBJECT(widget), text, NULL); |
576 sprintf(text, "_dw_sigdata%d", counter); | 576 snprintf(text, 100, "_dw_sigdata%d", counter); |
577 g_object_set_data(G_OBJECT(widget), text, NULL); | 577 g_object_set_data(G_OBJECT(widget), text, NULL); |
578 } | 578 } |
579 | 579 |
580 static int _dw_set_signal_handler(GObject *object, HWND window, void *func, gpointer data, void *intfunc, void *discfunc) | 580 static int _dw_set_signal_handler(GObject *object, HWND window, void *func, gpointer data, void *intfunc, void *discfunc) |
581 { | 581 { |
582 int counter = GPOINTER_TO_INT(g_object_get_data(object, "_dw_sigcounter")); | 582 int counter = GPOINTER_TO_INT(g_object_get_data(object, "_dw_sigcounter")); |
583 char text[100]; | 583 char text[101] = {0}; |
584 | 584 |
585 sprintf(text, "_dw_sigwindow%d", counter); | 585 snprintf(text, 100, "_dw_sigwindow%d", counter); |
586 g_object_set_data(object, text, (gpointer)window); | 586 g_object_set_data(object, text, (gpointer)window); |
587 sprintf(text, "_dw_sigfunc%d", counter); | 587 snprintf(text, 100, "_dw_sigfunc%d", counter); |
588 g_object_set_data(object, text, (gpointer)func); | 588 g_object_set_data(object, text, (gpointer)func); |
589 sprintf(text, "_dw_intfunc%d", counter); | 589 snprintf(text, 100, "_dw_intfunc%d", counter); |
590 g_object_set_data(object, text, (gpointer)intfunc); | 590 g_object_set_data(object, text, (gpointer)intfunc); |
591 sprintf(text, "_dw_discfunc%d", counter); | 591 snprintf(text, 100, "_dw_discfunc%d", counter); |
592 g_object_set_data(object, text, (gpointer)discfunc); | 592 g_object_set_data(object, text, (gpointer)discfunc); |
593 sprintf(text, "_dw_sigdata%d", counter); | 593 snprintf(text, 100, "_dw_sigdata%d", counter); |
594 g_object_set_data(object, text, (gpointer)data); | 594 g_object_set_data(object, text, (gpointer)data); |
595 | 595 |
596 counter++; | 596 counter++; |
597 g_object_set_data(object, "_dw_sigcounter", GINT_TO_POINTER(counter)); | 597 g_object_set_data(object, "_dw_sigcounter", GINT_TO_POINTER(counter)); |
598 | 598 |
601 | 601 |
602 static void _dw_set_signal_handler_id(GObject *object, int counter, gint cid) | 602 static void _dw_set_signal_handler_id(GObject *object, int counter, gint cid) |
603 { | 603 { |
604 if(cid > 0) | 604 if(cid > 0) |
605 { | 605 { |
606 char text[100]; | 606 char text[101] = {0}; |
607 | 607 |
608 sprintf(text, "_dw_sigcid%d", counter); | 608 snprintf(text, 100, "_dw_sigcid%d", counter); |
609 g_object_set_data(object, text, GINT_TO_POINTER(cid)); | 609 g_object_set_data(object, text, GINT_TO_POINTER(cid)); |
610 } | 610 } |
611 else | 611 else |
612 dw_debug("WARNING: Dynamic Windows failed to connect signal.\n"); | 612 dw_debug("WARNING: Dynamic Windows failed to connect signal.\n"); |
613 } | 613 } |