Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

conversion from ‘int’ to non-scalar type ‘std::__cxx11::string

2,157 views
Skip to first unread message

RM

unread,
Jul 31, 2020, 6:33:55 AM7/31/20
to
Napisałem coś takiego:
char *tmp_tmplt = const_cast<char *>("/tmp/dirtyphp_XXXXXX");
string tmp_filename = mkstemp(tmp_tmplt);
I mam błąd kompilacji:

src/obfuscator.cpp: In member function ‘std::__cxx11::string
obfuscator::check_not_allowed_syntax(std::__cxx11::string,
std::__cxx11::string, std::__cxx11::string)’:
src/obfuscator.cpp:147:34: error: conversion from ‘int’ to non-scalar
type ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’ requested
string tmp_filename = mkstemp(tmp_tmplt);
~~~~~~~^~~~~~~~~~~

Nie rozumiem tego błędu ponieważ tmp_tmplt jest typu char* a nie int.

RM

unread,
Jul 31, 2020, 6:41:52 AM7/31/20
to
Sorry I have mistaken newsgroup. Now in English:

I wrote:
char *tmp_tmplt = const_cast<char *>("/tmp/dirtyphp_XXXXXX");
string tmp_filename = mkstemp(tmp_tmplt);
And I have compilation error:

src/obfuscator.cpp: In member function ‘std::__cxx11::string
obfuscator::check_not_allowed_syntax(std::__cxx11::string,
std::__cxx11::string, std::__cxx11::string)’:
src/obfuscator.cpp:147:34: error: conversion from ‘int’ to non-scalar
type ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’ requested
string tmp_filename = mkstemp(tmp_tmplt);
~~~~~~~^~~~~~~~~~~
I don't understand the error because tmp_tmplt is of type char*, not int.

Bo Persson

unread,
Jul 31, 2020, 6:54:13 AM7/31/20
to
Yes, but what does msktemp return?

int mkstemp(char *template);

The compiler complains about trying to construct the std::string from
the int return value.


Another problem is that casting away const from the literal isn't going
to make it writable. I would expect a runtime error here when testing
the code.


Bo Persson

RM

unread,
Jul 31, 2020, 7:44:45 AM7/31/20
to
Thank you.
I corrected my code.

char tmp_filename[21] = "/tmp/dirtyphp_XXXXXX";
close(mkstemp(tmp_filename));

Keith Thompson

unread,
Jul 31, 2020, 2:01:34 PM7/31/20
to
Better:

char tmp_filename[] = "/tmp/dirtyphp_XXXXXX";

Let the compiler figure out how big it needs to be. (Computers are
really good at counting things.)

--
Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

RM

unread,
Jul 31, 2020, 2:37:48 PM7/31/20
to
W dniu 31.07.2020 o 20:01, Keith Thompson pisze:
> RM <robert_m...@wp.pl> writes:
>> Thank you.
>> I corrected my code.
>>
>> char tmp_filename[21] = "/tmp/dirtyphp_XXXXXX";
>> close(mkstemp(tmp_filename));
>
> Better:
>
> char tmp_filename[] = "/tmp/dirtyphp_XXXXXX";
>
> Let the compiler figure out how big it needs to be. (Computers are
> really good at counting things.)
>
Thank you again.

Juha Nieminen

unread,
Jul 31, 2020, 4:16:48 PM7/31/20
to
Keith Thompson <Keith.S.T...@gmail.com> wrote:
> Better:
>
> char tmp_filename[] = "/tmp/dirtyphp_XXXXXX";
>
> Let the compiler figure out how big it needs to be. (Computers are
> really good at counting things.)

Unless you, like, are intending to use std::sprintf() to set that
XXXX... part at runtime, and its length may vary.

Keith Thompson

unread,
Jul 31, 2020, 4:19:53 PM7/31/20
to
Which he isn't. That line was immediately followed by a call to
mkstemp().
0 new messages