Fossil SCM
fixed: json_cap_value() now returns NULL (instead of prematurely/fataly querying the db) if g.userUid has not been set (i.e. CLI mode).
Commit
96920e7c04746c55ceed6e24fc82879886cb8197
Parent
f047bbddb484880…
1 file changed
+15
-11
+15
-11
| --- src/json.c | ||
| +++ src/json.c | ||
| @@ -1908,21 +1908,25 @@ | ||
| 1908 | 1908 | ** Returned value is owned by the caller, and will only be NULL if |
| 1909 | 1909 | ** g.userUid is invalid or an out of memory error. Or, it turns out, |
| 1910 | 1910 | ** in CLI mode (where there is no logged-in user). |
| 1911 | 1911 | */ |
| 1912 | 1912 | cson_value * json_cap_value(){ |
| 1913 | - Stmt q; | |
| 1914 | - cson_value * val = NULL; | |
| 1915 | - db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid); | |
| 1916 | - if( db_step(&q)==SQLITE_ROW ){ | |
| 1917 | - char const * str = (char const *)sqlite3_column_text(q.pStmt,0); | |
| 1918 | - if( str ){ | |
| 1919 | - val = json_new_string(str); | |
| 1920 | - } | |
| 1921 | - } | |
| 1922 | - db_finalize(&q); | |
| 1923 | - return val; | |
| 1913 | + if(g.userUid<=0){ | |
| 1914 | + return NULL; | |
| 1915 | + }else{ | |
| 1916 | + Stmt q = empty_Stmt; | |
| 1917 | + cson_value * val = NULL; | |
| 1918 | + db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid); | |
| 1919 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 1920 | + char const * str = (char const *)sqlite3_column_text(q.pStmt,0); | |
| 1921 | + if( str ){ | |
| 1922 | + val = json_new_string(str); | |
| 1923 | + } | |
| 1924 | + } | |
| 1925 | + db_finalize(&q); | |
| 1926 | + return val; | |
| 1927 | + } | |
| 1924 | 1928 | } |
| 1925 | 1929 | |
| 1926 | 1930 | /* |
| 1927 | 1931 | ** Implementation for /json/cap |
| 1928 | 1932 | ** |
| 1929 | 1933 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -1908,21 +1908,25 @@ | |
| 1908 | ** Returned value is owned by the caller, and will only be NULL if |
| 1909 | ** g.userUid is invalid or an out of memory error. Or, it turns out, |
| 1910 | ** in CLI mode (where there is no logged-in user). |
| 1911 | */ |
| 1912 | cson_value * json_cap_value(){ |
| 1913 | Stmt q; |
| 1914 | cson_value * val = NULL; |
| 1915 | db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid); |
| 1916 | if( db_step(&q)==SQLITE_ROW ){ |
| 1917 | char const * str = (char const *)sqlite3_column_text(q.pStmt,0); |
| 1918 | if( str ){ |
| 1919 | val = json_new_string(str); |
| 1920 | } |
| 1921 | } |
| 1922 | db_finalize(&q); |
| 1923 | return val; |
| 1924 | } |
| 1925 | |
| 1926 | /* |
| 1927 | ** Implementation for /json/cap |
| 1928 | ** |
| 1929 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -1908,21 +1908,25 @@ | |
| 1908 | ** Returned value is owned by the caller, and will only be NULL if |
| 1909 | ** g.userUid is invalid or an out of memory error. Or, it turns out, |
| 1910 | ** in CLI mode (where there is no logged-in user). |
| 1911 | */ |
| 1912 | cson_value * json_cap_value(){ |
| 1913 | if(g.userUid<=0){ |
| 1914 | return NULL; |
| 1915 | }else{ |
| 1916 | Stmt q = empty_Stmt; |
| 1917 | cson_value * val = NULL; |
| 1918 | db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid); |
| 1919 | if( db_step(&q)==SQLITE_ROW ){ |
| 1920 | char const * str = (char const *)sqlite3_column_text(q.pStmt,0); |
| 1921 | if( str ){ |
| 1922 | val = json_new_string(str); |
| 1923 | } |
| 1924 | } |
| 1925 | db_finalize(&q); |
| 1926 | return val; |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | /* |
| 1931 | ** Implementation for /json/cap |
| 1932 | ** |
| 1933 |