[banshee] Add null check to avoid common podcast update NRE



commit f87e41e5df1b6479cc09923becfd2735dbb57a78
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Tue Jun 30 19:44:44 2009 -0500

    Add null check to avoid common podcast update NRE

 src/Libraries/Migo/Migo.Net/AsyncWebClient.cs |   41 +++++++++++++-----------
 1 files changed, 22 insertions(+), 19 deletions(-)
---
diff --git a/src/Libraries/Migo/Migo.Net/AsyncWebClient.cs b/src/Libraries/Migo/Migo.Net/AsyncWebClient.cs
index a8a3380..66b2c81 100644
--- a/src/Libraries/Migo/Migo.Net/AsyncWebClient.cs
+++ b/src/Libraries/Migo/Migo.Net/AsyncWebClient.cs
@@ -721,30 +721,33 @@ namespace Migo.Net
                     OnDownloadFileCompleted (errPtr, cancelledCpy, userStatePtr);
                     break;
                 case DownloadType.String:
-                    string s;
-                    try {
-                        s = Encoding.GetString (resultPtr).TrimStart ();
-    
-                        // Workaround if the string is a XML to set the encoding from it
-                        if (s.StartsWith("<?xml")) {
-                            Match match = encoding_regexp.Match (s);
-                            if (match.Success && match.Groups.Count > 0) {
-                                string encodingStr = match.Groups[1].Value;
-                                try {
-                                    Encoding enc = Encoding.GetEncoding (encodingStr);
-                                    if (!enc.Equals (Encoding)) {
-                                        s = enc.GetString (resultPtr);
-                                    }
-                                } catch (ArgumentException) {}
+                    string s = null;
+
+                    if (resultPtr != null) {
+                        try {
+                            s = Encoding.GetString (resultPtr).TrimStart ();
+        
+                            // Workaround if the string is a XML to set the encoding from it
+                            if (s.StartsWith("<?xml")) {
+                                Match match = encoding_regexp.Match (s);
+                                if (match.Success && match.Groups.Count > 0) {
+                                    string encodingStr = match.Groups[1].Value;
+                                    try {
+                                        Encoding enc = Encoding.GetEncoding (encodingStr);
+                                        if (!enc.Equals (Encoding)) {
+                                            s = enc.GetString (resultPtr);
+                                        }
+                                    } catch (ArgumentException) {}
+                                }
                             }
+                        } catch (Exception ex) {
+                            Hyena.Log.DebugException (ex);
+                            s = String.Empty;
                         }
-                    } catch (Exception ex) {
-                        Hyena.Log.DebugException (ex);
-                        s = String.Empty;
                     }
                 
                     OnDownloadStringCompleted (
-                        s, errPtr, cancelledCpy, userStatePtr
+                        s ?? "", errPtr, cancelledCpy, userStatePtr
                     );
                     break;
             }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]