Skip to content
  • Marc-André Lureau's avatar
    glog: fix crash on windows with --subsystem,windows app · 615b847d
    Marc-André Lureau authored and Matthias Clasen's avatar Matthias Clasen committed
    A windows application compiled with -Wl,--subsystem,windows has no
    console attached. When started from the start menu for ex, it will crash
    when a function attempt to use g_log:
    
     #10 0x00a21b26 in g_logv (log_domain=0xa842e1 <__func__.7668+329> "GLib", log_level=G_LOG_LEVEL_CRITICAL, format=0xa845c6 <__func__.7668+1070> "%s: assertion '%s' failed", args=0x28f2bc "PG"")
     #11 0x00a21bb1 in g_log (log_domain=0xa842e1 <__func__.7668+329> "GLib", log_level=G_LOG_LEVEL_CRITICAL, format=0xa845c6 <__func__.7668+1070> "%s: assertion '%s' failed") at gmessages.c:1337
     #12 0x00a22bac in g_return_if_fail_warning (log_domain=0xa842e1 <__func__.7668+329> "GLib", pretty_function=0xa84750 <__func__.65002> "g_log_writer_supports_color",
         expression=0xa844de <__func__.7668+838> "output_fd >= 0") at gmessages.c:2453
     #13 0x00a2239e in g_log_writer_supports_color (output_fd=-2) at gmessages.c:1826
     #14 0x00a226ac in g_log_writer_standard_streams (log_level=G_LOG_LEVEL_WARNING, fields=0x28f3c8, n_fields=4, user_data=0x0) at gmessages.c:2254
     #15 0x00a2290e in g_log_writer_default (log_level=G_LOG_LEVEL_WARNING, fields=0x28f3c8, n_fields=4, user_data=0x0) at gmessages.c:2357
    
    According to https://msdn.microsoft.com/en-us/library/zs6wbdhx.aspx:
    
    If stdout or stderr is not associated with an output stream (for
    example, in a Windows application without a console window), the file
    descriptor returned is -2. In previous versions, the file descriptor
    returned was -1. This change allows applications to distinguish this
    condition from an error.
    
    Check if the stream exists and has an associated descriptor and return
    G_LOG_WRITER_UNHANDLED if it's not the case.
    
    Fixes:
    https://bugzilla.gnome.org/show_bug.cgi?id=772511
    
    
    
    Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
    615b847d