From 445408d95bd54c28481ba26eff020325b4e4ee19 Mon Sep 17 00:00:00 2001 From: Matthew Kilgore Date: Sun, 20 Nov 2022 04:32:35 -0500 Subject: [PATCH] _StatusCode() should give the correct error on invalid handle type Passing a handle of the invalid type (Ex. TCP) to _StatusCode should give error 52, but it gies error 9. --- internal/c/libqb.cpp | 7 +++++++ tests/compile_tests/http/http_error.bas | 2 +- tests/compile_tests/http/http_error.output | 2 +- tests/compile_tests/http/invalid_url.bas | 2 +- tests/compile_tests/http/invalid_url.output | 4 ++-- tests/compile_tests/http/no_unstable_err.bas | 2 +- .../compile_tests/http/no_unstable_err.output | 2 +- .../http/statuscode_invalid_handle.bas | 18 ++++++++++++++++++ .../http/statuscode_invalid_handle.output | 3 +++ 9 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 tests/compile_tests/http/statuscode_invalid_handle.bas create mode 100644 tests/compile_tests/http/statuscode_invalid_handle.output diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index 799c39fdd..1ca4eb7ac 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -21706,6 +21706,13 @@ int32 func__statusCode(int32 handle) { } int real_handle = -(handle + 1); + + special_handle_struct *sh = (special_handle_struct *)list_get(special_handles, real_handle); + if (sh->type != special_handle_type::Http) { + error(52); + return -1; + } + int code = libqb_http_get_status_code(real_handle); if (code == -1) { diff --git a/tests/compile_tests/http/http_error.bas b/tests/compile_tests/http/http_error.bas index af75fd803..c7eb55711 100644 --- a/tests/compile_tests/http/http_error.bas +++ b/tests/compile_tests/http/http_error.bas @@ -15,5 +15,5 @@ Print _StatusCode(h&) System errorhand: -PRINT ERR; ERL +PRINT "Error:"; ERR; ", Line:"; _ERRORLINE RESUME NEXT diff --git a/tests/compile_tests/http/http_error.output b/tests/compile_tests/http/http_error.output index 4895ce118..1886c3ab5 100644 --- a/tests/compile_tests/http/http_error.output +++ b/tests/compile_tests/http/http_error.output @@ -1,4 +1,4 @@ - 5 0 +Error: 5 , Line: 6 0 -2 404 diff --git a/tests/compile_tests/http/invalid_url.bas b/tests/compile_tests/http/invalid_url.bas index fbbcd9e30..ee03022f5 100644 --- a/tests/compile_tests/http/invalid_url.bas +++ b/tests/compile_tests/http/invalid_url.bas @@ -13,5 +13,5 @@ Print h& System errorhand: -PRINT ERR; ERL +PRINT "Error:"; ERR; ", Line:"; _ERRORLINE RESUME NEXT diff --git a/tests/compile_tests/http/invalid_url.output b/tests/compile_tests/http/invalid_url.output index ea2f26f54..9f7b175eb 100644 --- a/tests/compile_tests/http/invalid_url.output +++ b/tests/compile_tests/http/invalid_url.output @@ -1,4 +1,4 @@ - 5 0 +Error: 5 , Line: 6 0 - 5 0 +Error: 5 , Line: 10 0 diff --git a/tests/compile_tests/http/no_unstable_err.bas b/tests/compile_tests/http/no_unstable_err.bas index cfe3ee9f5..1df419934 100644 --- a/tests/compile_tests/http/no_unstable_err.bas +++ b/tests/compile_tests/http/no_unstable_err.bas @@ -7,5 +7,5 @@ Print h& System errorhand: -PRINT ERR; ERL +PRINT "Error:"; ERR; ", Line:"; _ERRORLINE RESUME NEXT diff --git a/tests/compile_tests/http/no_unstable_err.output b/tests/compile_tests/http/no_unstable_err.output index bfd19251f..4e0455240 100644 --- a/tests/compile_tests/http/no_unstable_err.output +++ b/tests/compile_tests/http/no_unstable_err.output @@ -1,2 +1,2 @@ - 5 0 +Error: 5 , Line: 4 0 diff --git a/tests/compile_tests/http/statuscode_invalid_handle.bas b/tests/compile_tests/http/statuscode_invalid_handle.bas new file mode 100644 index 000000000..1292bf0ca --- /dev/null +++ b/tests/compile_tests/http/statuscode_invalid_handle.bas @@ -0,0 +1,18 @@ +$Unstable:Http +$Console:Only +ON ERROR GOTO errorhand + +h& = _OpenHost("TCP/IP:50000") + +' Error, invalid handle type +Print _StatusCode(h&) + +' Errors, invalid handle numbers +Print _StatusCode(0) +Print _StatusCode(20) + +System + +errorhand: +PRINT "Error:"; ERR; ", Line:"; _ERRORLINE +RESUME NEXT diff --git a/tests/compile_tests/http/statuscode_invalid_handle.output b/tests/compile_tests/http/statuscode_invalid_handle.output new file mode 100644 index 000000000..6c2ea9724 --- /dev/null +++ b/tests/compile_tests/http/statuscode_invalid_handle.output @@ -0,0 +1,3 @@ +Error: 52 , Line: 8 +Error: 52 , Line: 11 +Error: 52 , Line: 12